configgler 0.1.2 → 0.1.4
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/lib/configgler/config.rb +20 -4
- data/lib/configgler/version.rb +1 -1
- data/spec/configgler_spec.rb +20 -2
- data/spec/yaml/configgler_spec.yml +11 -11
- metadata +4 -4
data/lib/configgler/config.rb
CHANGED
@@ -12,7 +12,7 @@ module Configgler
|
|
12
12
|
|
13
13
|
def method_missing(name,*args)
|
14
14
|
el = ConfigElement.new(@config,name.to_s)
|
15
|
-
el.is_a?(Hash) ? el : el.value
|
15
|
+
el.element.is_a?(Hash) ? el : el.value
|
16
16
|
end
|
17
17
|
|
18
18
|
def get_by_array(args=[])
|
@@ -36,14 +36,30 @@ module Configgler
|
|
36
36
|
self
|
37
37
|
end
|
38
38
|
|
39
|
-
def method_missing(name)
|
39
|
+
def method_missing(name,*args)
|
40
40
|
el = ConfigElement.new(@element,name.to_s)
|
41
|
-
el.is_a?(Hash)
|
41
|
+
if el.element.is_a?(Hash)
|
42
|
+
args.length > 0 ? get_by_array(args,el.element) : el
|
43
|
+
else
|
44
|
+
el.element
|
45
|
+
end
|
42
46
|
end
|
43
|
-
|
47
|
+
|
44
48
|
def value
|
45
49
|
@element
|
46
50
|
end
|
51
|
+
|
52
|
+
def get_by_array(args)
|
53
|
+
c = @element[args.shift.to_s]
|
54
|
+
until args.length == 0
|
55
|
+
c = c[args.shift.to_s]
|
56
|
+
end
|
57
|
+
c
|
58
|
+
end
|
59
|
+
|
60
|
+
def get(*args)
|
61
|
+
get_by_array(args)
|
62
|
+
end
|
47
63
|
|
48
64
|
end
|
49
65
|
|
data/lib/configgler/version.rb
CHANGED
data/spec/configgler_spec.rb
CHANGED
@@ -3,13 +3,31 @@ require 'configgler'
|
|
3
3
|
|
4
4
|
describe Configgler do
|
5
5
|
|
6
|
-
describe '
|
6
|
+
describe 'load yaml file' do
|
7
7
|
it 'should load a yaml file' do
|
8
8
|
c = Configgler.load('configgler_spec.yml', File.dirname(__FILE__), 'yaml')
|
9
|
-
c.
|
9
|
+
c.is_a?(Configgler::Config).should == true
|
10
10
|
end
|
11
11
|
end
|
12
12
|
|
13
|
+
describe 'read values' do
|
14
|
+
|
15
|
+
it 'should navigate configuration values using list of keys [config.get(\'one\',\'two\',\'three\',\'four\')]' do
|
16
|
+
c = Configgler.load('configgler_spec.yml', File.dirname(__FILE__), 'yaml')
|
17
|
+
c.get('third','stuff','h1').should == 'foo'
|
18
|
+
end
|
19
|
+
|
20
|
+
it 'should navigate configuration values using dot-notation [config.one.two.three.four]' do
|
21
|
+
c = Configgler.load('configgler_spec.yml', File.dirname(__FILE__), 'yaml')
|
22
|
+
c.third.stuff.h1.should == 'foo'
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should navigate configuration values using mixed notation [config.one.two.get(\'three\',\'four\')]' do
|
26
|
+
c = Configgler.load('configgler_spec.yml', File.dirname(__FILE__), 'yaml')
|
27
|
+
c.third.get('stuff','h1').should == 'foo'
|
28
|
+
end
|
29
|
+
|
30
|
+
end
|
13
31
|
end
|
14
32
|
|
15
33
|
|
metadata
CHANGED
@@ -1,13 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configgler
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
hash:
|
4
|
+
hash: 19
|
5
5
|
prerelease:
|
6
6
|
segments:
|
7
7
|
- 0
|
8
8
|
- 1
|
9
|
-
-
|
10
|
-
version: 0.1.
|
9
|
+
- 4
|
10
|
+
version: 0.1.4
|
11
11
|
platform: ruby
|
12
12
|
authors:
|
13
13
|
- max sharples
|
@@ -15,7 +15,7 @@ autorequire:
|
|
15
15
|
bindir: bin
|
16
16
|
cert_chain: []
|
17
17
|
|
18
|
-
date: 2011-09-
|
18
|
+
date: 2011-09-21 00:00:00 Z
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
21
21
|
name: rspec
|