iqeo-conf 0.0.13 → 1.0.0

Sign up to get free protection for your applications and to get access to all the features.
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- iqeo-conf (0.0.13)
4
+ iqeo-conf (0.0.14)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -1,3 +1,3 @@
1
1
  module Iqeo
2
- CONFIGURATION_VERSION = "0.0.13"
2
+ CONFIGURATION_VERSION = "1.0.0"
3
3
  end
@@ -85,16 +85,12 @@ module Iqeo
85
85
  attr_accessor :_parent, :_items
86
86
 
87
87
  def initialize default = nil, &block
88
- # todo: default immediate child Configurations should have _parent updated
89
- @_items = case
90
- when default.kind_of?( HashWithIndifferentAccess ) then default
91
- when default.kind_of?( Configuration ) then default._items
92
- else HashWithIndifferentAccess.new
93
- end
88
+ @_items = HashWithIndifferentAccess.new
94
89
  @_parent = nil
90
+ _merge! default if default.kind_of?( Configuration )
95
91
  if block_given?
96
- if block.arity > 0 # cannot set parent for yield blocks here as self is wrong !?
97
- yield self
92
+ if block.arity > 0 # cannot set parent for yield block here as context is unknowable
93
+ yield self # parent is being set in new_defer_block_for_parent
98
94
  else
99
95
  if block.binding.eval('self').kind_of?( Configuration ) # for eval block if nested configuration
100
96
  @_parent = block.binding.eval('self') # set parent to make inherited values available
@@ -123,11 +119,7 @@ module Iqeo
123
119
  end
124
120
 
125
121
  def _set key, value
126
- # todo: extend parenting for enumerable with configurations at arbitrary depth
127
- case
128
- when value.kind_of?( Configuration ) then value._parent = self
129
- when value.kind_of?( Enumerable ) then value.each { |v| v._parent = self if v.kind_of? Configuration }
130
- end
122
+ value._parent = self if value.kind_of?( Configuration )
131
123
  @_items[key] = value
132
124
  end
133
125
  alias []= _set
@@ -140,8 +132,8 @@ module Iqeo
140
132
 
141
133
  def _get key
142
134
  return @_items[key] unless @_items[key].nil?
143
- return @_items[key] if _parent.nil?
144
- _parent._get key
135
+ return @_items[key] if @_parent.nil?
136
+ @_parent._get key
145
137
  end
146
138
  alias [] _get
147
139
 
@@ -154,17 +146,18 @@ module Iqeo
154
146
  end
155
147
 
156
148
  def _merge! other
157
- # todo: merges should update _parent of any immediate child Configurations
158
149
  @_items.merge! other._items
150
+ @_items.values.each do |value|
151
+ value._parent = self if value.kind_of?( Configuration )
152
+ end
159
153
  self
160
154
  end
161
155
 
162
156
  def _merge other
163
- # todo: merges should update _parent of any immediate child Configurations
164
157
  self.dup._merge! other
165
158
  end
166
159
 
167
- # todo: can :_parent= be protected ?
160
+ # todo: why can't :_parent= be protected ?
168
161
 
169
162
  protected :_parent, :_items, :_items=, :_get, :[], :_set, :[]=
170
163
 
@@ -262,18 +262,7 @@ describe Configuration do
262
262
  conf.should_not be_nil
263
263
  conf.alpha.bravo.__send__(:_parent).should be conf.alpha
264
264
  conf.alpha.__send__(:_parent).should be conf
265
- conf._parent.should be_nil
266
- end
267
-
268
- it 'knows its parent when contained in an enumerable' do
269
- conf = nil
270
- expect do
271
- conf = Configuration.new
272
- conf.alpha Configuration.new, Configuration.new, Configuration.new
273
- end.to_not raise_error
274
- conf.should_not be_nil
275
- conf.alpha.each { |child| child.__send__(:_parent).should be conf }
276
- conf._parent.should be_nil
265
+ conf.__send__(:_parent).should be_nil
277
266
  end
278
267
 
279
268
  it 'inherits settings' do
@@ -813,6 +802,7 @@ describe Configuration do
813
802
  conf.echo.should be :original1
814
803
  conf.hotel.should be :new
815
804
  conf.foxtrot.should be :overridden
805
+ conf.__send__(:_parent).should be nil
816
806
  conf.should be orig
817
807
  end
818
808
 
@@ -829,6 +819,63 @@ describe Configuration do
829
819
  conf.echo.should be :original1
830
820
  conf.hotel.should be :new
831
821
  conf.foxtrot.should be :overridden
822
+ conf.__send__(:_parent).should be nil
823
+ conf.should_not be orig
824
+ end
825
+
826
+ it 'can update with a nested configuration' do
827
+ orig = simple_explicit_configuration
828
+ orig.echo :original1
829
+ orig.foxtrot :original2
830
+ other = Configuration.new do
831
+ foxtrot :overridden
832
+ hotel :new
833
+ nested do
834
+ golf :also_new
835
+ hotel :overridden
836
+ echo :overridden
837
+ end
838
+ end
839
+ conf = orig._merge! other
840
+ simple_configuration_example conf
841
+ conf.echo.should be :original1
842
+ conf.hotel.should be :new
843
+ conf.foxtrot.should be :overridden
844
+ conf.nested.alpha.should be 1
845
+ conf.nested.echo.should be :overridden
846
+ conf.nested.foxtrot.should be :overridden
847
+ conf.nested.golf.should be :also_new
848
+ conf.nested.hotel.should be :overridden
849
+ conf.nested.__send__(:_parent).should be conf
850
+ conf.__send__(:_parent).should be nil
851
+ conf.should be orig
852
+ end
853
+
854
+ it 'can create with a nested configuration' do
855
+ orig = simple_explicit_configuration
856
+ orig.echo :original1
857
+ orig.foxtrot :original2
858
+ other = Configuration.new do
859
+ foxtrot :overridden
860
+ hotel :new
861
+ nested do
862
+ golf :also_new
863
+ hotel :overridden
864
+ echo :overridden
865
+ end
866
+ end
867
+ conf = orig._merge other
868
+ simple_configuration_example conf
869
+ conf.echo.should be :original1
870
+ conf.hotel.should be :new
871
+ conf.foxtrot.should be :overridden
872
+ conf.nested.alpha.should be 1
873
+ conf.nested.echo.should be :overridden
874
+ conf.nested.foxtrot.should be :overridden
875
+ conf.nested.golf.should be :also_new
876
+ conf.nested.hotel.should be :overridden
877
+ conf.nested.__send__(:_parent).should be conf
878
+ conf.__send__(:_parent).should be nil
832
879
  conf.should_not be orig
833
880
  end
834
881
 
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: iqeo-conf
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.13
4
+ version: 1.0.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: 2012-05-16 00:00:00.000000000 Z
12
+ date: 2012-05-18 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: rake