yaml_configuration 0.0.9 → 0.0.10

Sign up to get free protection for your applications and to get access to all the features.
@@ -4,6 +4,7 @@ module YamlConfiguration
4
4
  @config = hash_configuration
5
5
  @name = name
6
6
  @parent = parent
7
+ @placeholders_preprocessor = PlaceholdersPreprocessor.new(self)
7
8
  end
8
9
 
9
10
  def full_name(setting_name)
@@ -26,6 +27,10 @@ module YamlConfiguration
26
27
  end
27
28
  end
28
29
 
30
+ def respond_to_missing?(method, *)
31
+ asking_if_setting_exist(method.to_s) || setting_exist?(method.to_s) || super
32
+ end
33
+
29
34
  private
30
35
  def asking_if_setting_exist(setting_name)
31
36
  setting_name =~ /^(.*)+\?$/
@@ -40,7 +45,7 @@ module YamlConfiguration
40
45
  if value.respond_to?(:keys)
41
46
  return Configuration.new(value, self, setting_name)
42
47
  else
43
- return value
48
+ return @placeholders_preprocessor.parse(value)
44
49
  end
45
50
  end
46
51
  end
@@ -0,0 +1,15 @@
1
+ module YamlConfiguration
2
+ class PlaceholdersPreprocessor
3
+ def initialize(configuration)
4
+ @configuration = configuration
5
+ end
6
+
7
+ def parse(value)
8
+ if value.respond_to?(:each)
9
+ value.map {|v| self.parse(v)}
10
+ else
11
+ value.gsub(/\${([^}]*)}/) { @configuration.instance_eval($1) }
12
+ end
13
+ end
14
+ end
15
+ end
@@ -1,3 +1,3 @@
1
1
  module YamlConfiguration
2
- VERSION = "0.0.9"
2
+ VERSION = "0.0.10"
3
3
  end
@@ -1,5 +1,6 @@
1
1
  require "yaml_configuration/version"
2
2
  require 'hash_deep_merge'
3
+ require_relative 'yaml_configuration/placeholders_preprocessor'
3
4
  require_relative 'yaml_configuration/configuration'
4
5
  require_relative 'yaml_configuration/loader'
5
6
 
@@ -37,5 +37,27 @@ module YamlConfiguration
37
37
  assert configuration.site.name?
38
38
  refute configuration.site.database?
39
39
  end
40
+
41
+ def test_that_placeholder_get_replaced_correctly
42
+ configuration = Configuration.new({'host' => 'localhost', 'port' => '23',
43
+ 'base_url' => '${host}:${port}/${database.name}',
44
+ 'database' => { 'name' => 'mysql'}})
45
+
46
+ assert_equal 'localhost:23/mysql', configuration.base_url
47
+ end
48
+
49
+ def test_that_placeholders_get_replaced_correctly_in_arrays
50
+ urls = ['${host}:${port}/first',
51
+ '${host}:${port}/second',
52
+ ['${host}:${port}/third','${host}:${port}/fourth']
53
+ ]
54
+ configuration = Configuration.new({'host' => 'localhost', 'port' => '23',
55
+ 'urls' => urls})
56
+
57
+ assert_equal ['localhost:23/first',
58
+ 'localhost:23/second',
59
+ ['localhost:23/third', 'localhost:23/fourth'],
60
+ ], configuration.urls
61
+ end
40
62
  end
41
63
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: yaml_configuration
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.9
4
+ version: 0.0.10
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,11 +9,11 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2011-12-07 00:00:00.000000000Z
12
+ date: 2011-12-08 00:00:00.000000000Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: minitest
16
- requirement: &76870070 !ruby/object:Gem::Requirement
16
+ requirement: &83297040 !ruby/object:Gem::Requirement
17
17
  none: false
18
18
  requirements:
19
19
  - - ! '>='
@@ -21,10 +21,10 @@ dependencies:
21
21
  version: '0'
22
22
  type: :development
23
23
  prerelease: false
24
- version_requirements: *76870070
24
+ version_requirements: *83297040
25
25
  - !ruby/object:Gem::Dependency
26
26
  name: turn
27
- requirement: &76869790 !ruby/object:Gem::Requirement
27
+ requirement: &83296760 !ruby/object:Gem::Requirement
28
28
  none: false
29
29
  requirements:
30
30
  - - ! '>='
@@ -32,10 +32,10 @@ dependencies:
32
32
  version: '0'
33
33
  type: :development
34
34
  prerelease: false
35
- version_requirements: *76869790
35
+ version_requirements: *83296760
36
36
  - !ruby/object:Gem::Dependency
37
37
  name: ansi
38
- requirement: &76869410 !ruby/object:Gem::Requirement
38
+ requirement: &83296330 !ruby/object:Gem::Requirement
39
39
  none: false
40
40
  requirements:
41
41
  - - ! '>='
@@ -43,10 +43,10 @@ dependencies:
43
43
  version: '0'
44
44
  type: :development
45
45
  prerelease: false
46
- version_requirements: *76869410
46
+ version_requirements: *83296330
47
47
  - !ruby/object:Gem::Dependency
48
48
  name: hash-deep-merge
49
- requirement: &76868780 !ruby/object:Gem::Requirement
49
+ requirement: &83295850 !ruby/object:Gem::Requirement
50
50
  none: false
51
51
  requirements:
52
52
  - - ! '>='
@@ -54,7 +54,7 @@ dependencies:
54
54
  version: '0'
55
55
  type: :runtime
56
56
  prerelease: false
57
- version_requirements: *76868780
57
+ version_requirements: *83295850
58
58
  description: Load, merge and provide sensible error messages when using yaml based
59
59
  configuration
60
60
  email:
@@ -69,6 +69,7 @@ files:
69
69
  - lib/yaml_configuration.rb
70
70
  - lib/yaml_configuration/configuration.rb
71
71
  - lib/yaml_configuration/loader.rb
72
+ - lib/yaml_configuration/placeholders_preprocessor.rb
72
73
  - lib/yaml_configuration/version.rb
73
74
  - tests/tests_setup.rb
74
75
  - tests/yaml_configuration/configuration_tests.rb