configatron 4.1.1 → 4.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,7 @@
1
+ === 4.2.0
2
+
3
+ * [backwards-incompatible] Make to_h/to_hash recursively hashify Configatron::Stores, and resolve Configatron::Procs.
4
+
1
5
  === 4.1.1
2
6
 
3
7
  * Fix delayed attributes
@@ -1,4 +1,5 @@
1
1
  require 'singleton'
2
+ require 'forwardable'
2
3
 
3
4
  # This is the root configatron object, and contains methods which
4
5
  # operate on the entire configatron hierarchy.
@@ -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?
@@ -1,3 +1,3 @@
1
1
  class Configatron
2
- VERSION = "4.1.1"
2
+ VERSION = "4.2.0"
3
3
  end
@@ -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.1.1
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-24 00:00:00.000000000 Z
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: 2777108850332874749
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: 2777108850332874749
150
+ hash: -3864894795624167904
151
151
  requirements: []
152
152
  rubyforge_project:
153
153
  rubygems_version: 1.8.25