configgler 0.1.2 → 0.1.4

Sign up to get free protection for your applications and to get access to all the features.
@@ -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) ? el : el.value
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
 
@@ -1,3 +1,3 @@
1
1
  module Configgler
2
- VERSION = "0.1.2"
2
+ VERSION = "0.1.4"
3
3
  end
@@ -3,13 +3,31 @@ require 'configgler'
3
3
 
4
4
  describe Configgler do
5
5
 
6
- describe '#load' do
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.first.should == 1
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
 
@@ -1,15 +1,15 @@
1
1
  first: 1
2
2
  second:
3
- - 1
4
- - 2
5
- - 3
3
+ - 1
4
+ - 2
5
+ - 3
6
6
  third:
7
- hash:
8
- h1: foo
9
- h2: bar
10
- h3:
11
- - 1
12
- - 2
13
- - 3
14
- - 4
7
+ stuff:
8
+ h1: foo
9
+ h2: bar
10
+ h3:
11
+ - 1
12
+ - 2
13
+ - 3
14
+ - 4
15
15
  fourth: nil
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: 31
4
+ hash: 19
5
5
  prerelease:
6
6
  segments:
7
7
  - 0
8
8
  - 1
9
- - 2
10
- version: 0.1.2
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-19 00:00:00 Z
18
+ date: 2011-09-21 00:00:00 Z
19
19
  dependencies:
20
20
  - !ruby/object:Gem::Dependency
21
21
  name: rspec