configatron 4.1.1 → 4.2.0
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/History.txt +4 -0
- data/lib/configatron/root_store.rb +1 -0
- data/lib/configatron/store.rb +8 -2
- data/lib/configatron/version.rb +1 -1
- data/test/functional/configatron.rb +13 -0
- metadata +4 -4
data/History.txt
CHANGED
data/lib/configatron/store.rb
CHANGED
@@ -92,6 +92,13 @@ class Configatron
|
|
92
92
|
Store.new(@root_store, @name, @attributes.clone)
|
93
93
|
end
|
94
94
|
|
95
|
+
def to_h
|
96
|
+
@attributes.each_with_object({}) do |(k, v), h|
|
97
|
+
v = v.call if ::Configatron::Proc === v
|
98
|
+
h[k] = Store === v ? v.to_h : v
|
99
|
+
end
|
100
|
+
end
|
101
|
+
|
95
102
|
# So that puts works (it expects the object to respond to to_ary)
|
96
103
|
def to_ary
|
97
104
|
nil
|
@@ -127,12 +134,11 @@ class Configatron
|
|
127
134
|
|
128
135
|
alias :[]= :store
|
129
136
|
alias :has_key? :key?
|
137
|
+
alias :to_hash :to_h
|
130
138
|
|
131
139
|
def_delegator :@attributes, :values
|
132
140
|
def_delegator :@attributes, :keys
|
133
141
|
def_delegator :@attributes, :each
|
134
|
-
def_delegator :@attributes, :to_h
|
135
|
-
def_delegator :@attributes, :to_hash
|
136
142
|
def_delegator :@attributes, :delete
|
137
143
|
# def_delegator :@attributes, :fetch
|
138
144
|
# def_delegator :@attributes, :has_key?
|
data/lib/configatron/version.rb
CHANGED
@@ -94,4 +94,17 @@ class Critic::Functional::ConfigatronTest < Critic::Functional::Test
|
|
94
94
|
assert_equal('hi', @kernel.foo.catch)
|
95
95
|
end
|
96
96
|
end
|
97
|
+
|
98
|
+
describe 'to_h and to_hash' do
|
99
|
+
before do
|
100
|
+
@kernel.a = 1
|
101
|
+
@kernel.b.c = Configatron::Delayed.new{ @kernel.a + 3 }
|
102
|
+
end
|
103
|
+
|
104
|
+
it 'returns a hash representation' do
|
105
|
+
expected_hash = { a: 1, b: { c: 4 } }
|
106
|
+
assert_equal(expected_hash, @kernel.to_h)
|
107
|
+
assert_equal(expected_hash, @kernel.to_hash)
|
108
|
+
end
|
109
|
+
end
|
97
110
|
end
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: configatron
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 4.
|
4
|
+
version: 4.2.0
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2014-06-
|
12
|
+
date: 2014-06-25 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rake
|
@@ -138,7 +138,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
138
138
|
version: '0'
|
139
139
|
segments:
|
140
140
|
- 0
|
141
|
-
hash:
|
141
|
+
hash: -3864894795624167904
|
142
142
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
143
143
|
none: false
|
144
144
|
requirements:
|
@@ -147,7 +147,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
147
147
|
version: '0'
|
148
148
|
segments:
|
149
149
|
- 0
|
150
|
-
hash:
|
150
|
+
hash: -3864894795624167904
|
151
151
|
requirements: []
|
152
152
|
rubyforge_project:
|
153
153
|
rubygems_version: 1.8.25
|