iqeo-conf 1.0.0 → 1.0.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.yardoc/checksums +2 -2
- data/.yardoc/objects/root.dat +0 -0
- data/Gemfile.lock +1 -1
- data/README.md +1 -1
- data/doc/Iqeo.html +2 -2
- data/doc/Iqeo/BlankSlate.html +1 -1
- data/doc/Iqeo/Configuration.html +44 -42
- data/doc/_index.html +1 -1
- data/doc/file.README.html +2 -2
- data/doc/index.html +2 -2
- data/doc/top-level-namespace.html +1 -1
- data/lib/iqeo/configuration.rb +7 -3
- data/lib/iqeo/configuration/version.rb +1 -1
- data/spec/configuration_spec.rb +722 -644
- metadata +2 -2
data/.yardoc/checksums
CHANGED
@@ -1,2 +1,2 @@
|
|
1
|
-
lib/iqeo/configuration.rb
|
2
|
-
lib/iqeo/configuration/version.rb
|
1
|
+
lib/iqeo/configuration.rb fb776784916e7a38f6424d31f66a5da06b446532
|
2
|
+
lib/iqeo/configuration/version.rb c2a9c241b633aea27196848bec6b5e9069315361
|
data/.yardoc/objects/root.dat
CHANGED
Binary file
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -119,7 +119,7 @@ conf.collect { |key,value| value } # => [ 1, 2.0, :three, 'four' ]
|
|
119
119
|
* read from string, at creation, or after - merged & nested
|
120
120
|
* load from filename, at creation, or after - merged & nested
|
121
121
|
* defaults
|
122
|
-
* merge configurations
|
122
|
+
* merge configurations recursively
|
123
123
|
* blank slate for DSL
|
124
124
|
|
125
125
|
## Fancy usage
|
data/doc/Iqeo.html
CHANGED
@@ -115,7 +115,7 @@
|
|
115
115
|
<dt id="CONFIGURATION_VERSION-constant" class="">CONFIGURATION_VERSION =
|
116
116
|
|
117
117
|
</dt>
|
118
|
-
<dd><pre class="code"><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>
|
118
|
+
<dd><pre class="code"><span class='tstring'><span class='tstring_beg'>"</span><span class='tstring_content'>1.0.1</span><span class='tstring_end'>"</span></span></pre></dd>
|
119
119
|
|
120
120
|
</dl>
|
121
121
|
|
@@ -131,7 +131,7 @@
|
|
131
131
|
</div>
|
132
132
|
|
133
133
|
<div id="footer">
|
134
|
-
Generated on
|
134
|
+
Generated on Mon May 21 15:18:24 2012 by
|
135
135
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
136
136
|
0.8.1 (ruby-1.9.3).
|
137
137
|
</div>
|
data/doc/Iqeo/BlankSlate.html
CHANGED
@@ -115,7 +115,7 @@
|
|
115
115
|
</div>
|
116
116
|
|
117
117
|
<div id="footer">
|
118
|
-
Generated on
|
118
|
+
Generated on Mon May 21 15:18:24 2012 by
|
119
119
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
120
120
|
0.8.1 (ruby-1.9.3).
|
121
121
|
</div>
|
data/doc/Iqeo/Configuration.html
CHANGED
@@ -454,27 +454,19 @@
|
|
454
454
|
98
|
455
455
|
99
|
456
456
|
100
|
457
|
-
101
|
458
|
-
102
|
459
|
-
103
|
460
|
-
104
|
461
|
-
105</pre>
|
457
|
+
101</pre>
|
462
458
|
</td>
|
463
459
|
<td>
|
464
460
|
<pre class="code"><span class="info file"># File 'lib/iqeo/configuration.rb', line 87</span>
|
465
461
|
|
466
462
|
<span class='kw'>def</span> <span class='id identifier rubyid_initialize'>initialize</span> <span class='id identifier rubyid_default'>default</span> <span class='op'>=</span> <span class='kw'>nil</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span>
|
467
|
-
<span class='
|
468
|
-
</span> <span class='ivar'>@_items</span> <span class='op'>=</span> <span class='kw'>case</span>
|
469
|
-
<span class='kw'>when</span> <span class='id identifier rubyid_default'>default</span><span class='period'>.</span><span class='id identifier rubyid_kind_of?'>kind_of?</span><span class='lparen'>(</span> <span class='const'>HashWithIndifferentAccess</span> <span class='rparen'>)</span> <span class='kw'>then</span> <span class='id identifier rubyid_default'>default</span>
|
470
|
-
<span class='kw'>when</span> <span class='id identifier rubyid_default'>default</span><span class='period'>.</span><span class='id identifier rubyid_kind_of?'>kind_of?</span><span class='lparen'>(</span> <span class='const'>Configuration</span> <span class='rparen'>)</span> <span class='kw'>then</span> <span class='id identifier rubyid_default'>default</span><span class='period'>.</span><span class='id identifier rubyid__items'>_items</span>
|
471
|
-
<span class='kw'>else</span> <span class='const'>HashWithIndifferentAccess</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
|
472
|
-
<span class='kw'>end</span>
|
463
|
+
<span class='ivar'>@_items</span> <span class='op'>=</span> <span class='const'>HashWithIndifferentAccess</span><span class='period'>.</span><span class='id identifier rubyid_new'>new</span>
|
473
464
|
<span class='ivar'>@_parent</span> <span class='op'>=</span> <span class='kw'>nil</span>
|
465
|
+
<span class='id identifier rubyid__merge!'>_merge!</span> <span class='id identifier rubyid_default'>default</span> <span class='kw'>if</span> <span class='id identifier rubyid_default'>default</span><span class='period'>.</span><span class='id identifier rubyid_kind_of?'>kind_of?</span><span class='lparen'>(</span> <span class='const'>Configuration</span> <span class='rparen'>)</span>
|
474
466
|
<span class='kw'>if</span> <span class='id identifier rubyid_block_given?'>block_given?</span>
|
475
|
-
<span class='kw'>if</span> <span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='id identifier rubyid_arity'>arity</span> <span class='op'>></span> <span class='int'>0</span>
|
476
|
-
</span> <span class='kw'>yield</span> <span class='kw'>self</span>
|
477
|
-
<span class='kw'>else</span>
|
467
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='id identifier rubyid_arity'>arity</span> <span class='op'>></span> <span class='int'>0</span> <span class='comment'># cannot set parent for yield block here as context is unknowable
|
468
|
+
</span> <span class='kw'>yield</span> <span class='kw'>self</span> <span class='comment'># parent is being set in new_defer_block_for_parent
|
469
|
+
</span> <span class='kw'>else</span>
|
478
470
|
<span class='kw'>if</span> <span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='id identifier rubyid_binding'>binding</span><span class='period'>.</span><span class='id identifier rubyid_eval'>eval</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>self</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span><span class='period'>.</span><span class='id identifier rubyid_kind_of?'>kind_of?</span><span class='lparen'>(</span> <span class='const'>Configuration</span> <span class='rparen'>)</span> <span class='comment'># for eval block if nested configuration
|
479
471
|
</span> <span class='ivar'>@_parent</span> <span class='op'>=</span> <span class='id identifier rubyid_block'>block</span><span class='period'>.</span><span class='id identifier rubyid_binding'>binding</span><span class='period'>.</span><span class='id identifier rubyid_eval'>eval</span><span class='lparen'>(</span><span class='tstring'><span class='tstring_beg'>'</span><span class='tstring_content'>self</span><span class='tstring_end'>'</span></span><span class='rparen'>)</span> <span class='comment'># set parent to make inherited values available
|
480
472
|
</span> <span class='kw'>end</span> <span class='comment'># during block execution
|
@@ -510,6 +502,10 @@
|
|
510
502
|
<pre class="lines">
|
511
503
|
|
512
504
|
|
505
|
+
103
|
506
|
+
104
|
507
|
+
105
|
508
|
+
106
|
513
509
|
107
|
514
510
|
108
|
515
511
|
109
|
@@ -522,14 +518,10 @@
|
|
522
518
|
116
|
523
519
|
117
|
524
520
|
118
|
525
|
-
119
|
526
|
-
120
|
527
|
-
121
|
528
|
-
122
|
529
|
-
123</pre>
|
521
|
+
119</pre>
|
530
522
|
</td>
|
531
523
|
<td>
|
532
|
-
<pre class="code"><span class="info file"># File 'lib/iqeo/configuration.rb', line
|
524
|
+
<pre class="code"><span class="info file"># File 'lib/iqeo/configuration.rb', line 103</span>
|
533
525
|
|
534
526
|
<span class='kw'>def</span> <span class='id identifier rubyid_method_missing'>method_missing</span> <span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_values'>values</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span>
|
535
527
|
<span class='kw'>return</span> <span class='ivar'>@_items</span><span class='period'>.</span><span class='id identifier rubyid_send'>send</span><span class='lparen'>(</span> <span class='id identifier rubyid_name'>name</span><span class='comma'>,</span> <span class='op'>*</span><span class='id identifier rubyid_values'>values</span><span class='comma'>,</span> <span class='op'>&</span><span class='id identifier rubyid_block'>block</span> <span class='rparen'>)</span> <span class='kw'>if</span> <span class='ivar'>@_items</span><span class='period'>.</span><span class='id identifier rubyid_respond_to?'>respond_to?</span> <span class='id identifier rubyid_name'>name</span> <span class='comment'># @_items methods are highest priority
|
@@ -821,12 +813,12 @@
|
|
821
813
|
<pre class="lines">
|
822
814
|
|
823
815
|
|
824
|
-
|
825
|
-
|
826
|
-
|
816
|
+
144
|
817
|
+
145
|
818
|
+
146</pre>
|
827
819
|
</td>
|
828
820
|
<td>
|
829
|
-
<pre class="code"><span class="info file"># File 'lib/iqeo/configuration.rb', line
|
821
|
+
<pre class="code"><span class="info file"># File 'lib/iqeo/configuration.rb', line 144</span>
|
830
822
|
|
831
823
|
<span class='kw'>def</span> <span class='id identifier rubyid__load'>_load</span> <span class='id identifier rubyid_file'>file</span>
|
832
824
|
<span class='id identifier rubyid__read'>_read</span> <span class='id identifier rubyid_file'>file</span><span class='period'>.</span><span class='id identifier rubyid_respond_to?'>respond_to?</span><span class='lparen'>(</span><span class='symbol'>:read</span><span class='rparen'>)</span> <span class='op'>?</span> <span class='id identifier rubyid_file'>file</span><span class='period'>.</span><span class='id identifier rubyid_read'>read</span> <span class='op'>:</span> <span class='const'>File</span><span class='period'>.</span><span class='id identifier rubyid_read'>read</span><span class='lparen'>(</span><span class='id identifier rubyid_file'>file</span><span class='rparen'>)</span>
|
@@ -851,17 +843,15 @@
|
|
851
843
|
<pre class="lines">
|
852
844
|
|
853
845
|
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
165</pre>
|
846
|
+
160
|
847
|
+
161
|
848
|
+
162</pre>
|
858
849
|
</td>
|
859
850
|
<td>
|
860
|
-
<pre class="code"><span class="info file"># File 'lib/iqeo/configuration.rb', line
|
851
|
+
<pre class="code"><span class="info file"># File 'lib/iqeo/configuration.rb', line 160</span>
|
861
852
|
|
862
853
|
<span class='kw'>def</span> <span class='id identifier rubyid__merge'>_merge</span> <span class='id identifier rubyid_other'>other</span>
|
863
|
-
<span class='
|
864
|
-
</span> <span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_dup'>dup</span><span class='period'>.</span><span class='id identifier rubyid__merge!'>_merge!</span> <span class='id identifier rubyid_other'>other</span>
|
854
|
+
<span class='kw'>self</span><span class='period'>.</span><span class='id identifier rubyid_dup'>dup</span><span class='period'>.</span><span class='id identifier rubyid__merge!'>_merge!</span> <span class='id identifier rubyid_other'>other</span>
|
865
855
|
<span class='kw'>end</span></pre>
|
866
856
|
</td>
|
867
857
|
</tr>
|
@@ -883,18 +873,30 @@
|
|
883
873
|
<pre class="lines">
|
884
874
|
|
885
875
|
|
876
|
+
148
|
877
|
+
149
|
878
|
+
150
|
879
|
+
151
|
880
|
+
152
|
881
|
+
153
|
882
|
+
154
|
883
|
+
155
|
886
884
|
156
|
887
885
|
157
|
888
|
-
158
|
889
|
-
159
|
890
|
-
160</pre>
|
886
|
+
158</pre>
|
891
887
|
</td>
|
892
888
|
<td>
|
893
|
-
<pre class="code"><span class="info file"># File 'lib/iqeo/configuration.rb', line
|
889
|
+
<pre class="code"><span class="info file"># File 'lib/iqeo/configuration.rb', line 148</span>
|
894
890
|
|
895
891
|
<span class='kw'>def</span> <span class='id identifier rubyid__merge!'>_merge!</span> <span class='id identifier rubyid_other'>other</span>
|
896
|
-
<span class='
|
897
|
-
</span>
|
892
|
+
<span class='ivar'>@_items</span><span class='period'>.</span><span class='id identifier rubyid_merge!'>merge!</span><span class='lparen'>(</span><span class='id identifier rubyid_other'>other</span><span class='period'>.</span><span class='id identifier rubyid__items'>_items</span><span class='rparen'>)</span> <span class='kw'>do</span> <span class='op'>|</span><span class='id identifier rubyid_key'>key</span><span class='comma'>,</span><span class='id identifier rubyid_this'>this</span><span class='comma'>,</span><span class='id identifier rubyid_other'>other</span><span class='op'>|</span>
|
893
|
+
<span class='kw'>if</span> <span class='id identifier rubyid_this'>this</span><span class='period'>.</span><span class='id identifier rubyid_kind_of?'>kind_of?</span><span class='lparen'>(</span> <span class='const'>Configuration</span> <span class='rparen'>)</span> <span class='op'>&&</span> <span class='id identifier rubyid_other'>other</span><span class='period'>.</span><span class='id identifier rubyid_kind_of?'>kind_of?</span><span class='lparen'>(</span> <span class='const'>Configuration</span> <span class='rparen'>)</span>
|
894
|
+
<span class='id identifier rubyid_this'>this</span><span class='period'>.</span><span class='id identifier rubyid__merge!'>_merge!</span> <span class='id identifier rubyid_other'>other</span>
|
895
|
+
<span class='kw'>else</span>
|
896
|
+
<span class='id identifier rubyid_other'>other</span>
|
897
|
+
<span class='kw'>end</span>
|
898
|
+
<span class='kw'>end</span>
|
899
|
+
<span class='ivar'>@_items</span><span class='period'>.</span><span class='id identifier rubyid_values'>values</span><span class='period'>.</span><span class='id identifier rubyid_each'>each</span> <span class='lbrace'>{</span> <span class='op'>|</span><span class='id identifier rubyid_value'>value</span><span class='op'>|</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid__parent'>_parent</span> <span class='op'>=</span> <span class='kw'>self</span> <span class='kw'>if</span> <span class='id identifier rubyid_value'>value</span><span class='period'>.</span><span class='id identifier rubyid_kind_of?'>kind_of?</span><span class='lparen'>(</span> <span class='const'>Configuration</span> <span class='rparen'>)</span> <span class='rbrace'>}</span>
|
898
900
|
<span class='kw'>self</span>
|
899
901
|
<span class='kw'>end</span></pre>
|
900
902
|
</td>
|
@@ -917,12 +919,12 @@
|
|
917
919
|
<pre class="lines">
|
918
920
|
|
919
921
|
|
920
|
-
|
921
|
-
|
922
|
-
|
922
|
+
140
|
923
|
+
141
|
924
|
+
142</pre>
|
923
925
|
</td>
|
924
926
|
<td>
|
925
|
-
<pre class="code"><span class="info file"># File 'lib/iqeo/configuration.rb', line
|
927
|
+
<pre class="code"><span class="info file"># File 'lib/iqeo/configuration.rb', line 140</span>
|
926
928
|
|
927
929
|
<span class='kw'>def</span> <span class='id identifier rubyid__read'>_read</span> <span class='id identifier rubyid_string'>string</span>
|
928
930
|
<span class='id identifier rubyid_instance_eval'>instance_eval</span> <span class='id identifier rubyid_string'>string</span>
|
@@ -937,7 +939,7 @@
|
|
937
939
|
</div>
|
938
940
|
|
939
941
|
<div id="footer">
|
940
|
-
Generated on
|
942
|
+
Generated on Mon May 21 15:18:24 2012 by
|
941
943
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
942
944
|
0.8.1 (ruby-1.9.3).
|
943
945
|
</div>
|
data/doc/_index.html
CHANGED
@@ -131,7 +131,7 @@
|
|
131
131
|
</div>
|
132
132
|
|
133
133
|
<div id="footer">
|
134
|
-
Generated on
|
134
|
+
Generated on Mon May 21 15:18:24 2012 by
|
135
135
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
136
136
|
0.8.1 (ruby-1.9.3).
|
137
137
|
</div>
|
data/doc/file.README.html
CHANGED
@@ -176,7 +176,7 @@ Configuration settings can be retrieved directly or indirectly.</p>
|
|
176
176
|
<li>read from string, at creation, or after - merged & nested</li>
|
177
177
|
<li>load from filename, at creation, or after - merged & nested</li>
|
178
178
|
<li>defaults</li>
|
179
|
-
<li>merge configurations</li>
|
179
|
+
<li>merge configurations recursively</li>
|
180
180
|
<li>blank slate for DSL</li>
|
181
181
|
</ul>
|
182
182
|
|
@@ -197,7 +197,7 @@ See LICENSE file.</p>
|
|
197
197
|
</div></div>
|
198
198
|
|
199
199
|
<div id="footer">
|
200
|
-
Generated on
|
200
|
+
Generated on Mon May 21 15:18:24 2012 by
|
201
201
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
202
202
|
0.8.1 (ruby-1.9.3).
|
203
203
|
</div>
|
data/doc/index.html
CHANGED
@@ -176,7 +176,7 @@ Configuration settings can be retrieved directly or indirectly.</p>
|
|
176
176
|
<li>read from string, at creation, or after - merged & nested</li>
|
177
177
|
<li>load from filename, at creation, or after - merged & nested</li>
|
178
178
|
<li>defaults</li>
|
179
|
-
<li>merge configurations</li>
|
179
|
+
<li>merge configurations recursively</li>
|
180
180
|
<li>blank slate for DSL</li>
|
181
181
|
</ul>
|
182
182
|
|
@@ -197,7 +197,7 @@ See LICENSE file.</p>
|
|
197
197
|
</div></div>
|
198
198
|
|
199
199
|
<div id="footer">
|
200
|
-
Generated on
|
200
|
+
Generated on Mon May 21 15:18:24 2012 by
|
201
201
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
202
202
|
0.8.1 (ruby-1.9.3).
|
203
203
|
</div>
|
@@ -103,7 +103,7 @@
|
|
103
103
|
</div>
|
104
104
|
|
105
105
|
<div id="footer">
|
106
|
-
Generated on
|
106
|
+
Generated on Mon May 21 15:18:24 2012 by
|
107
107
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
108
108
|
0.8.1 (ruby-1.9.3).
|
109
109
|
</div>
|
data/lib/iqeo/configuration.rb
CHANGED
@@ -146,10 +146,14 @@ module Iqeo
|
|
146
146
|
end
|
147
147
|
|
148
148
|
def _merge! other
|
149
|
-
@_items.merge!
|
150
|
-
|
151
|
-
|
149
|
+
@_items.merge!(other._items) do |key,this,other|
|
150
|
+
if this.kind_of?( Configuration ) && other.kind_of?( Configuration )
|
151
|
+
this._merge! other
|
152
|
+
else
|
153
|
+
other
|
154
|
+
end
|
152
155
|
end
|
156
|
+
@_items.values.each { |value| value._parent = self if value.kind_of?( Configuration ) }
|
153
157
|
self
|
154
158
|
end
|
155
159
|
|
data/spec/configuration_spec.rb
CHANGED
@@ -39,449 +39,329 @@ describe Configuration do
|
|
39
39
|
conf.echo.foxtrot.should be_true
|
40
40
|
end
|
41
41
|
|
42
|
-
|
43
|
-
Configuration.version.should == CONFIGURATION_VERSION
|
44
|
-
end
|
45
|
-
|
46
|
-
context 'at creation' do
|
47
|
-
|
48
|
-
it 'does not require a block' do
|
49
|
-
Configuration.new.should be_a Configuration
|
50
|
-
end
|
51
|
-
|
52
|
-
it 'accept a block with arity 0' do
|
53
|
-
Configuration.new { }.should be_a Configuration
|
54
|
-
end
|
55
|
-
|
56
|
-
it 'instance_eval a block with arity 0' do
|
57
|
-
conf_eval = nil
|
58
|
-
conf_new = Configuration.new { conf_eval = self }
|
59
|
-
conf_new.should be conf_eval
|
60
|
-
end
|
61
|
-
|
62
|
-
it 'accept a block with arity 1' do
|
63
|
-
Configuration.new { |arg| }.should be_a Configuration
|
64
|
-
end
|
42
|
+
context 'v1.0' do
|
65
43
|
|
66
|
-
it '
|
67
|
-
|
68
|
-
conf_new = Configuration.new { |conf| conf_yielded = conf }
|
69
|
-
conf_new.should be conf_yielded
|
44
|
+
it 'reports the correct version' do
|
45
|
+
Configuration.version.should == CONFIGURATION_VERSION
|
70
46
|
end
|
71
47
|
|
72
|
-
|
73
|
-
Configuration.new { |arg1,arg2,arg3| }.should be_a Configuration
|
74
|
-
end
|
75
|
-
|
76
|
-
it 'yield self to block with arity > 1' do
|
77
|
-
conf_yielded = nil
|
78
|
-
conf_new = Configuration.new { |conf,arg1,arg2| conf_yielded = conf }
|
79
|
-
conf_new.should be conf_yielded
|
80
|
-
end
|
81
|
-
|
82
|
-
|
83
|
-
it 'accepts defaults from another configuration' do
|
84
|
-
conf = Configuration.new simple_explicit_configuration
|
85
|
-
simple_configuration_example conf
|
86
|
-
end
|
87
|
-
|
88
|
-
it 'overrides defaults from another configuration' do
|
89
|
-
conf_default = Configuration.new( simple_explicit_configuration ) { echo true }
|
90
|
-
conf_default.echo.should be_true
|
91
|
-
conf = Configuration.new( conf_default ) { echo false }
|
92
|
-
simple_configuration_example conf
|
93
|
-
conf.echo.should be_false
|
94
|
-
end
|
48
|
+
context 'at creation' do
|
95
49
|
|
96
|
-
|
97
|
-
|
98
|
-
it 'simple eval DSL from string' do
|
99
|
-
simple_configuration_example Configuration.read simple_eval_string
|
50
|
+
it 'does not require a block' do
|
51
|
+
Configuration.new.should be_a Configuration
|
100
52
|
end
|
101
53
|
|
102
|
-
it '
|
103
|
-
|
54
|
+
it 'accept a block with arity 0' do
|
55
|
+
Configuration.new { }.should be_a Configuration
|
104
56
|
end
|
105
57
|
|
106
|
-
it '
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
simple_configuration_example Configuration.load file
|
58
|
+
it 'instance_eval a block with arity 0' do
|
59
|
+
conf_eval = nil
|
60
|
+
conf_new = Configuration.new { conf_eval = self }
|
61
|
+
conf_new.should be conf_eval
|
111
62
|
end
|
112
63
|
|
113
|
-
it '
|
114
|
-
|
115
|
-
simple_configuration_example Configuration.load "filename"
|
64
|
+
it 'accept a block with arity 1' do
|
65
|
+
Configuration.new { |arg| }.should be_a Configuration
|
116
66
|
end
|
117
67
|
|
118
|
-
it '
|
119
|
-
|
120
|
-
|
121
|
-
|
122
|
-
delta do
|
123
|
-
echo true
|
124
|
-
end
|
125
|
-
end"
|
126
|
-
conf = Configuration.read string
|
127
|
-
conf.should_not be_nil
|
128
|
-
conf.alpha.should be_true
|
129
|
-
conf.bravo.should be_a Configuration
|
130
|
-
conf.bravo.alpha should be_true
|
131
|
-
conf.bravo.charlie should be_true
|
132
|
-
conf.bravo.delta.should be_a Configuration
|
133
|
-
conf.bravo.delta.alpha.should be_true
|
134
|
-
conf.bravo.delta.charlie.should be_true
|
135
|
-
conf.bravo.delta.echo.should be_true
|
68
|
+
it 'yield self to block with arity 1' do
|
69
|
+
conf_yielded = nil
|
70
|
+
conf_new = Configuration.new { |conf| conf_yielded = conf }
|
71
|
+
conf_new.should be conf_yielded
|
136
72
|
end
|
137
73
|
|
138
|
-
|
74
|
+
it 'accept a block with arity > 1' do
|
75
|
+
Configuration.new { |arg1,arg2,arg3| }.should be_a Configuration
|
76
|
+
end
|
139
77
|
|
140
|
-
|
78
|
+
it 'yield self to block with arity > 1' do
|
79
|
+
conf_yielded = nil
|
80
|
+
conf_new = Configuration.new { |conf,arg1,arg2| conf_yielded = conf }
|
81
|
+
conf_new.should be conf_yielded
|
82
|
+
end
|
141
83
|
|
142
|
-
context 'settings retrieval' do
|
143
84
|
|
144
|
-
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
it 'delegates hash methods to internal hash' do
|
149
|
-
conf = Configuration.new
|
150
|
-
conf.alpha 1
|
151
|
-
conf.bravo 2
|
152
|
-
conf.charlie 3
|
153
|
-
conf.delta 4
|
154
|
-
conf.should_not be_nil
|
155
|
-
sum = 0
|
156
|
-
expect do
|
157
|
-
conf.each { |k,v| sum += v }
|
158
|
-
end.to_not raise_error
|
159
|
-
sum.should == 10
|
160
|
-
conf.size.should == 4
|
161
|
-
end
|
85
|
+
it 'accepts defaults from another configuration' do
|
86
|
+
conf = Configuration.new simple_explicit_configuration
|
87
|
+
simple_configuration_example conf
|
88
|
+
end
|
162
89
|
|
163
|
-
|
90
|
+
it 'overrides defaults from another configuration' do
|
91
|
+
conf_default = Configuration.new( simple_explicit_configuration ) { echo true }
|
92
|
+
conf_default.echo.should be_true
|
93
|
+
conf = Configuration.new( conf_default ) { echo false }
|
94
|
+
simple_configuration_example conf
|
95
|
+
conf.echo.should be_false
|
96
|
+
end
|
164
97
|
|
165
|
-
|
98
|
+
context 'can load' do
|
166
99
|
|
167
|
-
|
168
|
-
|
169
|
-
|
100
|
+
it 'simple eval DSL from string' do
|
101
|
+
simple_configuration_example Configuration.read simple_eval_string
|
102
|
+
end
|
170
103
|
|
171
|
-
|
172
|
-
|
173
|
-
|
174
|
-
conf.bravo = { :a => 1, :b => 2, :c => 3 }
|
175
|
-
conf.alpha.should == [ :a, :b, :c] and conf.alpha.should be_an Array
|
176
|
-
conf.alpha.size.should == 3
|
177
|
-
conf.alpha[0].should == :a
|
178
|
-
conf.alpha[1].should == :b
|
179
|
-
conf.alpha[2].should == :c
|
180
|
-
conf.bravo.should == { 'a' => 1, 'b' => 2, 'c' => 3} and conf.bravo.should be_a Hash
|
181
|
-
conf.bravo.size.should == 3
|
182
|
-
conf.bravo[:a].should == 1
|
183
|
-
conf.bravo[:b].should == 2
|
184
|
-
conf.bravo[:c].should == 3
|
185
|
-
end
|
104
|
+
it 'simple eval DSL from file (StringIO)' do
|
105
|
+
simple_configuration_example Configuration.load StringIO.new simple_eval_string
|
106
|
+
end
|
186
107
|
|
187
|
-
|
108
|
+
it 'simple eval DSL from file (mock & expected methods)' do
|
109
|
+
file = mock
|
110
|
+
file.should_receive( :respond_to? ).with( :read ).and_return true
|
111
|
+
file.should_receive( :read ).and_return simple_eval_string
|
112
|
+
simple_configuration_example Configuration.load file
|
113
|
+
end
|
188
114
|
|
189
|
-
|
115
|
+
it 'simple eval DSL from filename (expected methods)' do
|
116
|
+
File.should_receive( :read ).with( "filename" ).and_return simple_eval_string
|
117
|
+
simple_configuration_example Configuration.load "filename"
|
118
|
+
end
|
190
119
|
|
191
|
-
|
192
|
-
|
193
|
-
|
194
|
-
|
195
|
-
|
120
|
+
it 'complex eval DSL from string' do
|
121
|
+
string = "alpha true
|
122
|
+
bravo do
|
123
|
+
charlie true
|
124
|
+
delta do
|
125
|
+
echo true
|
126
|
+
end
|
127
|
+
end"
|
128
|
+
conf = Configuration.read string
|
129
|
+
conf.should_not be_nil
|
130
|
+
conf.alpha.should be_true
|
131
|
+
conf.bravo.should be_a Configuration
|
132
|
+
conf.bravo.alpha should be_true
|
133
|
+
conf.bravo.charlie should be_true
|
134
|
+
conf.bravo.delta.should be_a Configuration
|
135
|
+
conf.bravo.delta.alpha.should be_true
|
136
|
+
conf.bravo.delta.charlie.should be_true
|
137
|
+
conf.bravo.delta.echo.should be_true
|
138
|
+
end
|
196
139
|
|
197
|
-
|
198
|
-
conf = nil
|
199
|
-
expect do
|
200
|
-
conf = Configuration.new
|
201
|
-
conf.alpha :a, :b, :c
|
202
|
-
end.to_not raise_error
|
203
|
-
conf.should_not be_nil
|
204
|
-
conf.alpha.should == [ :a, :b, :c ] and conf.alpha.should be_an Array
|
205
|
-
end
|
140
|
+
end # loads
|
206
141
|
|
207
|
-
|
208
|
-
conf = Configuration.new
|
209
|
-
conf.alpha 1, 2, 3, :a => 4, :b => 5, :c => 6
|
210
|
-
conf.alpha.should == [ 1, 2, 3, { 'a' => 4, 'b' => 5, 'c' => 6} ] and conf.alpha.should be_a Array
|
211
|
-
end
|
142
|
+
end # creation
|
212
143
|
|
213
|
-
|
144
|
+
context 'settings retrieval' do
|
214
145
|
|
215
|
-
|
146
|
+
it 'returns nil for non-existent settings' do
|
147
|
+
simple_explicit_configuration.not_a_setting.should be_nil
|
148
|
+
end
|
216
149
|
|
217
|
-
|
218
|
-
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
150
|
+
it 'delegates hash methods to internal hash' do
|
151
|
+
conf = Configuration.new
|
152
|
+
conf.alpha 1
|
153
|
+
conf.bravo 2
|
154
|
+
conf.charlie 3
|
155
|
+
conf.delta 4
|
156
|
+
conf.should_not be_nil
|
157
|
+
sum = 0
|
158
|
+
expect do
|
159
|
+
conf.each { |k,v| sum += v }
|
160
|
+
end.to_not raise_error
|
161
|
+
sum.should == 10
|
162
|
+
conf.size.should == 4
|
163
|
+
end
|
225
164
|
|
226
|
-
|
227
|
-
conf = nil
|
228
|
-
expect do
|
229
|
-
conf = Configuration.new
|
230
|
-
conf['alpha'] = 1
|
231
|
-
end.to_not raise_error
|
232
|
-
conf.should_not be_nil
|
233
|
-
conf['alpha'].should == 1
|
234
|
-
end
|
165
|
+
end # settings retrieval
|
235
166
|
|
236
|
-
|
167
|
+
context 'single value setting' do
|
237
168
|
|
238
|
-
|
169
|
+
it 'accepts simple values' do
|
170
|
+
simple_configuration_example simple_explicit_configuration
|
171
|
+
end
|
239
172
|
|
240
|
-
|
241
|
-
conf = nil
|
242
|
-
expect do
|
173
|
+
it 'accepts complex values' do
|
243
174
|
conf = Configuration.new
|
244
|
-
conf.alpha
|
245
|
-
conf.
|
246
|
-
conf.alpha.
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
175
|
+
conf.alpha = [ :a, :b, :c ]
|
176
|
+
conf.bravo = { :a => 1, :b => 2, :c => 3 }
|
177
|
+
conf.alpha.should == [ :a, :b, :c] and conf.alpha.should be_an Array
|
178
|
+
conf.alpha.size.should == 3
|
179
|
+
conf.alpha[0].should == :a
|
180
|
+
conf.alpha[1].should == :b
|
181
|
+
conf.alpha[2].should == :c
|
182
|
+
conf.bravo.should == { 'a' => 1, 'b' => 2, 'c' => 3} and conf.bravo.should be_a Hash
|
183
|
+
conf.bravo.size.should == 3
|
184
|
+
conf.bravo[:a].should == 1
|
185
|
+
conf.bravo[:b].should == 2
|
186
|
+
conf.bravo[:c].should == 3
|
187
|
+
end
|
253
188
|
|
254
|
-
|
255
|
-
conf = nil
|
256
|
-
expect do
|
257
|
-
conf = Configuration.new
|
258
|
-
conf.alpha Configuration.new
|
259
|
-
conf.alpha.bravo Configuration.new
|
260
|
-
conf.alpha.bravo.charlie true
|
261
|
-
end.to_not raise_error
|
262
|
-
conf.should_not be_nil
|
263
|
-
conf.alpha.bravo.__send__(:_parent).should be conf.alpha
|
264
|
-
conf.alpha.__send__(:_parent).should be conf
|
265
|
-
conf.__send__(:_parent).should be_nil
|
266
|
-
end
|
189
|
+
end # single value setting
|
267
190
|
|
268
|
-
|
269
|
-
conf = nil
|
270
|
-
expect do
|
271
|
-
conf = Configuration.new
|
272
|
-
conf.alpha Configuration.new
|
273
|
-
conf.alpha.bravo Configuration.new
|
274
|
-
conf.top = true
|
275
|
-
conf.alpha.middle = true
|
276
|
-
conf.alpha.bravo.bottom = true
|
277
|
-
end.to_not raise_error
|
278
|
-
conf.should_not be_nil
|
279
|
-
conf.top.should be_true
|
280
|
-
conf.alpha.top.should be_true
|
281
|
-
conf.alpha.middle.should be_true
|
282
|
-
conf.alpha.bravo.top.should be_true
|
283
|
-
conf.alpha.bravo.middle.should be_true
|
284
|
-
conf.alpha.bravo.bottom.should be_true
|
285
|
-
end
|
191
|
+
context 'multiple value setting' do
|
286
192
|
|
287
|
-
|
288
|
-
conf = nil
|
289
|
-
expect do
|
193
|
+
it 'accepts hash without brackets' do
|
290
194
|
conf = Configuration.new
|
291
|
-
conf.alpha
|
292
|
-
conf.alpha.
|
293
|
-
conf.level = 1
|
294
|
-
conf.alpha.level = 2
|
295
|
-
conf.alpha.bravo.level = 3
|
296
|
-
end.to_not raise_error
|
297
|
-
conf.should_not be_nil
|
298
|
-
conf.level.should == 1
|
299
|
-
conf.alpha.level.should == 2
|
300
|
-
conf.alpha.bravo.level.should == 3
|
301
|
-
end
|
302
|
-
|
303
|
-
end # nested configuration
|
304
|
-
|
305
|
-
context 'mode of usage' do
|
306
|
-
|
307
|
-
context 'explicit' do
|
308
|
-
|
309
|
-
it 'accepts settings without =' do
|
310
|
-
conf = nil
|
311
|
-
expect do
|
312
|
-
conf = Configuration.new
|
313
|
-
conf.alpha :value
|
314
|
-
end.to_not raise_error
|
315
|
-
conf.should_not be_nil
|
316
|
-
conf.alpha.should == :value
|
195
|
+
conf.alpha :a => 1, :b => 2, :c => 3
|
196
|
+
conf.alpha.should == { 'a' => 1, 'b' => 2, 'c' => 3} and conf.alpha.should be_a Hash
|
317
197
|
end
|
318
198
|
|
319
|
-
it '
|
199
|
+
it 'treats multiple values as an array' do
|
320
200
|
conf = nil
|
321
201
|
expect do
|
322
202
|
conf = Configuration.new
|
323
|
-
conf.alpha
|
203
|
+
conf.alpha :a, :b, :c
|
324
204
|
end.to_not raise_error
|
325
205
|
conf.should_not be_nil
|
326
|
-
conf.alpha.should == :
|
206
|
+
conf.alpha.should == [ :a, :b, :c ] and conf.alpha.should be_an Array
|
327
207
|
end
|
328
208
|
|
329
|
-
it '
|
330
|
-
conf =
|
331
|
-
|
332
|
-
|
333
|
-
conf.alpha = :value
|
334
|
-
conf.bravo = conf.alpha
|
335
|
-
conf.charlie conf.bravo
|
336
|
-
end.to_not raise_error
|
337
|
-
conf.should_not be_nil
|
338
|
-
conf.alpha.should == :value
|
339
|
-
conf.bravo.should == :value
|
340
|
-
conf.charlie.should == :value
|
209
|
+
it 'treats hash without brackets after multiple values as last element of array' do
|
210
|
+
conf = Configuration.new
|
211
|
+
conf.alpha 1, 2, 3, :a => 4, :b => 5, :c => 6
|
212
|
+
conf.alpha.should == [ 1, 2, 3, { 'a' => 4, 'b' => 5, 'c' => 6} ] and conf.alpha.should be_a Array
|
341
213
|
end
|
342
214
|
|
343
|
-
|
215
|
+
end # multiple value setting
|
216
|
+
|
217
|
+
context 'hash operators [] & []= access' do
|
218
|
+
|
219
|
+
it 'accepts symbol keys' do
|
344
220
|
conf = nil
|
345
221
|
expect do
|
346
222
|
conf = Configuration.new
|
347
|
-
conf
|
223
|
+
conf[:alpha] = 1
|
348
224
|
end.to_not raise_error
|
349
|
-
conf.
|
350
|
-
conf.alpha.should == :value
|
351
|
-
conf.bravo.should == :value
|
225
|
+
conf[:alpha].should == 1
|
352
226
|
end
|
353
227
|
|
354
|
-
it '
|
228
|
+
it 'accepts non-symbol (string) keys' do
|
355
229
|
conf = nil
|
356
230
|
expect do
|
357
231
|
conf = Configuration.new
|
358
|
-
conf
|
359
|
-
conf.bravo Configuration.new
|
360
|
-
conf.bravo.charlie true
|
361
|
-
conf.bravo.delta Configuration.new
|
362
|
-
conf.bravo.delta.echo true
|
232
|
+
conf['alpha'] = 1
|
363
233
|
end.to_not raise_error
|
364
234
|
conf.should_not be_nil
|
365
|
-
conf
|
366
|
-
conf.bravo.should be_a Configuration
|
367
|
-
conf.bravo.alpha should be_true
|
368
|
-
conf.bravo.charlie should be_true
|
369
|
-
conf.bravo.delta.should be_a Configuration
|
370
|
-
conf.bravo.delta.alpha.should be_true
|
371
|
-
conf.bravo.delta.charlie.should be_true
|
372
|
-
conf.bravo.delta.echo.should be_true
|
235
|
+
conf['alpha'].should == 1
|
373
236
|
end
|
374
237
|
|
375
|
-
end #
|
238
|
+
end # hash operators [] & []= access
|
376
239
|
|
377
|
-
context '
|
240
|
+
context 'nested configuration' do
|
378
241
|
|
379
|
-
it '
|
242
|
+
it 'is supported' do
|
380
243
|
conf = nil
|
381
244
|
expect do
|
382
|
-
conf = Configuration.new
|
383
|
-
|
384
|
-
|
245
|
+
conf = Configuration.new
|
246
|
+
conf.alpha Configuration.new
|
247
|
+
conf.alpha.bravo Configuration.new
|
248
|
+
conf.alpha.bravo.charlie true
|
385
249
|
end.to_not raise_error
|
386
250
|
conf.should_not be_nil
|
387
|
-
conf.alpha.should
|
251
|
+
conf.alpha.should be_a Configuration
|
252
|
+
conf.alpha.bravo.should be_a Configuration
|
253
|
+
conf.alpha.bravo.charlie.should be_true
|
388
254
|
end
|
389
255
|
|
390
|
-
it '
|
256
|
+
it 'knows its parent when referenced directly' do
|
391
257
|
conf = nil
|
392
258
|
expect do
|
393
|
-
conf = Configuration.new
|
394
|
-
|
395
|
-
|
259
|
+
conf = Configuration.new
|
260
|
+
conf.alpha Configuration.new
|
261
|
+
conf.alpha.bravo Configuration.new
|
262
|
+
conf.alpha.bravo.charlie true
|
396
263
|
end.to_not raise_error
|
397
264
|
conf.should_not be_nil
|
398
|
-
conf.alpha.should
|
265
|
+
conf.alpha.bravo.__send__(:_parent).should be conf.alpha
|
266
|
+
conf.alpha.__send__(:_parent).should be conf
|
267
|
+
conf.__send__(:_parent).should be_nil
|
399
268
|
end
|
400
269
|
|
401
|
-
it '
|
270
|
+
it 'inherits settings' do
|
402
271
|
conf = nil
|
403
272
|
expect do
|
404
|
-
conf = Configuration.new
|
405
|
-
|
406
|
-
|
407
|
-
|
408
|
-
|
273
|
+
conf = Configuration.new
|
274
|
+
conf.alpha Configuration.new
|
275
|
+
conf.alpha.bravo Configuration.new
|
276
|
+
conf.top = true
|
277
|
+
conf.alpha.middle = true
|
278
|
+
conf.alpha.bravo.bottom = true
|
409
279
|
end.to_not raise_error
|
410
280
|
conf.should_not be_nil
|
411
|
-
conf.
|
412
|
-
conf.
|
413
|
-
conf.
|
281
|
+
conf.top.should be_true
|
282
|
+
conf.alpha.top.should be_true
|
283
|
+
conf.alpha.middle.should be_true
|
284
|
+
conf.alpha.bravo.top.should be_true
|
285
|
+
conf.alpha.bravo.middle.should be_true
|
286
|
+
conf.alpha.bravo.bottom.should be_true
|
414
287
|
end
|
415
288
|
|
416
|
-
it '
|
289
|
+
it 'can override inherited settings' do
|
417
290
|
conf = nil
|
418
291
|
expect do
|
419
|
-
conf = Configuration.new
|
420
|
-
|
421
|
-
|
292
|
+
conf = Configuration.new
|
293
|
+
conf.alpha Configuration.new
|
294
|
+
conf.alpha.bravo Configuration.new
|
295
|
+
conf.level = 1
|
296
|
+
conf.alpha.level = 2
|
297
|
+
conf.alpha.bravo.level = 3
|
422
298
|
end.to_not raise_error
|
423
299
|
conf.should_not be_nil
|
424
|
-
conf.
|
425
|
-
conf.
|
300
|
+
conf.level.should == 1
|
301
|
+
conf.alpha.level.should == 2
|
302
|
+
conf.alpha.bravo.level.should == 3
|
426
303
|
end
|
427
304
|
|
428
|
-
|
305
|
+
end # nested configuration
|
306
|
+
|
307
|
+
context 'mode of usage' do
|
429
308
|
|
430
|
-
|
309
|
+
context 'explicit' do
|
310
|
+
|
311
|
+
it 'accepts settings without =' do
|
431
312
|
conf = nil
|
432
313
|
expect do
|
433
|
-
conf = Configuration.new
|
434
|
-
|
435
|
-
c1.bravo do |c2|
|
436
|
-
c2.charlie true
|
437
|
-
c2.delta do |c3|
|
438
|
-
c3.echo true
|
439
|
-
end
|
440
|
-
end
|
441
|
-
end
|
314
|
+
conf = Configuration.new
|
315
|
+
conf.alpha :value
|
442
316
|
end.to_not raise_error
|
443
317
|
conf.should_not be_nil
|
444
|
-
conf.alpha.should
|
445
|
-
conf.bravo.should be_a Configuration
|
446
|
-
conf.bravo.alpha should be_true
|
447
|
-
conf.bravo.charlie should be_true
|
448
|
-
conf.bravo.delta.should be_a Configuration
|
449
|
-
conf.bravo.delta.alpha.should be_true
|
450
|
-
conf.bravo.delta.charlie.should be_true
|
451
|
-
conf.bravo.delta.echo.should be_true
|
318
|
+
conf.alpha.should == :value
|
452
319
|
end
|
453
320
|
|
454
|
-
it '
|
321
|
+
it 'accepts settings with =' do
|
455
322
|
conf = nil
|
456
323
|
expect do
|
457
|
-
conf = Configuration.new
|
324
|
+
conf = Configuration.new
|
325
|
+
conf.alpha = :value
|
458
326
|
end.to_not raise_error
|
459
327
|
conf.should_not be_nil
|
460
|
-
conf.alpha.should
|
461
|
-
conf.bravo.should be_a Configuration
|
462
|
-
conf.bravo.alpha should be_true
|
463
|
-
conf.bravo.charlie should be_true
|
464
|
-
conf.bravo.delta.should be_a Configuration
|
465
|
-
conf.bravo.delta.alpha.should be_true
|
466
|
-
conf.bravo.delta.charlie.should be_true
|
467
|
-
conf.bravo.delta.echo.should be_true
|
328
|
+
conf.alpha.should == :value
|
468
329
|
end
|
469
330
|
|
470
|
-
it 'can refer to an
|
331
|
+
it 'can refer to an existing setting' do
|
471
332
|
conf = nil
|
472
333
|
expect do
|
473
|
-
conf = Configuration.new
|
474
|
-
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
334
|
+
conf = Configuration.new
|
335
|
+
conf.alpha = :value
|
336
|
+
conf.bravo = conf.alpha
|
337
|
+
conf.charlie conf.bravo
|
338
|
+
end.to_not raise_error
|
339
|
+
conf.should_not be_nil
|
340
|
+
conf.alpha.should == :value
|
341
|
+
conf.bravo.should == :value
|
342
|
+
conf.charlie.should == :value
|
343
|
+
end
|
344
|
+
|
345
|
+
it 'returns value when creating/changing a setting' do
|
346
|
+
conf = nil
|
347
|
+
expect do
|
348
|
+
conf = Configuration.new
|
349
|
+
conf.bravo = conf.alpha = :value
|
350
|
+
end.to_not raise_error
|
351
|
+
conf.should_not be_nil
|
352
|
+
conf.alpha.should == :value
|
353
|
+
conf.bravo.should == :value
|
354
|
+
end
|
355
|
+
|
356
|
+
it 'supports nested configuration via Configuration.new' do
|
357
|
+
conf = nil
|
358
|
+
expect do
|
359
|
+
conf = Configuration.new
|
360
|
+
conf.alpha true
|
361
|
+
conf.bravo Configuration.new
|
362
|
+
conf.bravo.charlie true
|
363
|
+
conf.bravo.delta Configuration.new
|
364
|
+
conf.bravo.delta.echo true
|
485
365
|
end.to_not raise_error
|
486
366
|
conf.should_not be_nil
|
487
367
|
conf.alpha.should be_true
|
@@ -492,394 +372,592 @@ describe Configuration do
|
|
492
372
|
conf.bravo.delta.alpha.should be_true
|
493
373
|
conf.bravo.delta.charlie.should be_true
|
494
374
|
conf.bravo.delta.echo.should be_true
|
495
|
-
conf.bravo.delta.golf.should be_true
|
496
|
-
conf.bravo.foxtrot.should be_true
|
497
|
-
conf.hotel.should be_true
|
498
375
|
end
|
499
376
|
|
500
|
-
end #
|
377
|
+
end # explicit
|
501
378
|
|
502
|
-
context '
|
379
|
+
context 'yield DSL' do
|
503
380
|
|
504
|
-
it 'settings
|
505
|
-
conf =
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
conf.
|
381
|
+
it 'accepts settings without =' do
|
382
|
+
conf = nil
|
383
|
+
expect do
|
384
|
+
conf = Configuration.new do |c|
|
385
|
+
c.alpha :value
|
386
|
+
end
|
387
|
+
end.to_not raise_error
|
388
|
+
conf.should_not be_nil
|
389
|
+
conf.alpha.should == :value
|
512
390
|
end
|
513
391
|
|
514
|
-
it 'settings
|
515
|
-
conf =
|
516
|
-
|
517
|
-
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
conf.
|
392
|
+
it 'accepts settings with =' do
|
393
|
+
conf = nil
|
394
|
+
expect do
|
395
|
+
conf = Configuration.new do |c|
|
396
|
+
c.alpha = :value
|
397
|
+
end
|
398
|
+
end.to_not raise_error
|
399
|
+
conf.should_not be_nil
|
400
|
+
conf.alpha.should == :value
|
522
401
|
end
|
523
402
|
|
524
|
-
it '
|
525
|
-
conf =
|
526
|
-
|
527
|
-
|
528
|
-
|
403
|
+
it 'can refer to an existing setting' do
|
404
|
+
conf = nil
|
405
|
+
expect do
|
406
|
+
conf = Configuration.new do |c|
|
407
|
+
c.alpha = :value
|
408
|
+
c.bravo = c.alpha
|
409
|
+
c.charlie c.bravo
|
529
410
|
end
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
411
|
+
end.to_not raise_error
|
412
|
+
conf.should_not be_nil
|
413
|
+
conf.alpha.should == :value
|
414
|
+
conf.bravo.should == :value
|
415
|
+
conf.charlie.should == :value
|
534
416
|
end
|
535
417
|
|
536
|
-
it '
|
537
|
-
conf =
|
538
|
-
|
539
|
-
|
540
|
-
|
418
|
+
it 'returns value when creating/changing a setting' do
|
419
|
+
conf = nil
|
420
|
+
expect do
|
421
|
+
conf = Configuration.new do |c|
|
422
|
+
c.bravo = c.alpha = :value
|
541
423
|
end
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
|
424
|
+
end.to_not raise_error
|
425
|
+
conf.should_not be_nil
|
426
|
+
conf.alpha.should == :value
|
427
|
+
conf.bravo.should == :value
|
546
428
|
end
|
547
429
|
|
548
|
-
|
549
|
-
|
550
|
-
|
551
|
-
|
552
|
-
|
430
|
+
context 'nested configuration' do
|
431
|
+
|
432
|
+
it 'supported via do..end' do
|
433
|
+
conf = nil
|
434
|
+
expect do
|
435
|
+
conf = Configuration.new do |c1|
|
436
|
+
c1.alpha true
|
437
|
+
c1.bravo do |c2|
|
438
|
+
c2.charlie true
|
439
|
+
c2.delta do |c3|
|
440
|
+
c3.echo true
|
441
|
+
end
|
442
|
+
end
|
443
|
+
end
|
444
|
+
end.to_not raise_error
|
445
|
+
conf.should_not be_nil
|
446
|
+
conf.alpha.should be_true
|
447
|
+
conf.bravo.should be_a Configuration
|
448
|
+
conf.bravo.alpha should be_true
|
449
|
+
conf.bravo.charlie should be_true
|
450
|
+
conf.bravo.delta.should be_a Configuration
|
451
|
+
conf.bravo.delta.alpha.should be_true
|
452
|
+
conf.bravo.delta.charlie.should be_true
|
453
|
+
conf.bravo.delta.echo.should be_true
|
454
|
+
end
|
553
455
|
|
554
|
-
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
|
456
|
+
it 'supported via {..}' do
|
457
|
+
conf = nil
|
458
|
+
expect do
|
459
|
+
conf = Configuration.new { |c1| c1.alpha true ; c1.bravo { |c2| c2.charlie true ; c2.delta { |c3| c3.echo true } } }
|
460
|
+
end.to_not raise_error
|
461
|
+
conf.should_not be_nil
|
462
|
+
conf.alpha.should be_true
|
463
|
+
conf.bravo.should be_a Configuration
|
464
|
+
conf.bravo.alpha should be_true
|
465
|
+
conf.bravo.charlie should be_true
|
466
|
+
conf.bravo.delta.should be_a Configuration
|
467
|
+
conf.bravo.delta.alpha.should be_true
|
468
|
+
conf.bravo.delta.charlie.should be_true
|
469
|
+
conf.bravo.delta.echo.should be_true
|
559
470
|
end
|
560
|
-
end.to_not raise_error
|
561
|
-
conf.should_not be_nil
|
562
|
-
conf.alpha.should == :value
|
563
|
-
end
|
564
471
|
|
565
|
-
|
566
|
-
|
567
|
-
|
568
|
-
|
569
|
-
|
570
|
-
|
571
|
-
|
472
|
+
it 'can refer to an inherited setting' do
|
473
|
+
conf = nil
|
474
|
+
expect do
|
475
|
+
conf = Configuration.new do |c1|
|
476
|
+
c1.alpha true
|
477
|
+
c1.hotel c1.alpha
|
478
|
+
c1.bravo do |c2|
|
479
|
+
c2.charlie true
|
480
|
+
c2.foxtrot c2.alpha
|
481
|
+
c2.delta do |c3|
|
482
|
+
c3.echo true
|
483
|
+
c3.golf c3.alpha
|
484
|
+
end
|
485
|
+
end
|
486
|
+
end
|
487
|
+
end.to_not raise_error
|
488
|
+
conf.should_not be_nil
|
489
|
+
conf.alpha.should be_true
|
490
|
+
conf.bravo.should be_a Configuration
|
491
|
+
conf.bravo.alpha should be_true
|
492
|
+
conf.bravo.charlie should be_true
|
493
|
+
conf.bravo.delta.should be_a Configuration
|
494
|
+
conf.bravo.delta.alpha.should be_true
|
495
|
+
conf.bravo.delta.charlie.should be_true
|
496
|
+
conf.bravo.delta.echo.should be_true
|
497
|
+
conf.bravo.delta.golf.should be_true
|
498
|
+
conf.bravo.foxtrot.should be_true
|
499
|
+
conf.hotel.should be_true
|
572
500
|
end
|
573
|
-
end.to_not raise_error
|
574
|
-
conf.should_not be_nil
|
575
|
-
conf.alpha.should be_nil
|
576
|
-
conf.bravo.should == :value
|
577
|
-
alpha.should == :value # local alpha set by matching variables
|
578
|
-
end
|
579
501
|
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
586
|
-
|
502
|
+
end # nested configuration
|
503
|
+
|
504
|
+
context 'can load' do
|
505
|
+
|
506
|
+
it 'settings into the current configuration from a string' do
|
507
|
+
conf = Configuration.new do |c|
|
508
|
+
c.alpha false
|
509
|
+
c._read simple_eval_string
|
510
|
+
c.echo true
|
511
|
+
end
|
512
|
+
simple_configuration_example conf
|
513
|
+
conf.echo.should be_true
|
587
514
|
end
|
588
|
-
end.to_not raise_error
|
589
|
-
conf.should_not be_nil
|
590
|
-
conf.alpha.should == :value
|
591
|
-
conf.bravo.should == :value
|
592
|
-
conf.charlie.should == :value
|
593
|
-
end
|
594
515
|
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
516
|
+
it 'settings into the current configuration from a file (StringIO)' do
|
517
|
+
conf = Configuration.new do |c|
|
518
|
+
c.alpha false
|
519
|
+
c._load StringIO.new simple_eval_string
|
520
|
+
c.echo true
|
521
|
+
end
|
522
|
+
simple_configuration_example conf
|
523
|
+
conf.echo.should be_true
|
600
524
|
end
|
601
|
-
end.to_not raise_error
|
602
|
-
conf.should_not be_nil
|
603
|
-
conf.alpha.should == :value
|
604
|
-
conf.bravo.should == :value
|
605
|
-
end
|
606
525
|
|
607
|
-
|
526
|
+
it 'settings into a nested configuration from a string' do
|
527
|
+
conf = Configuration.new do |c|
|
528
|
+
c.alpha true
|
529
|
+
c.bravo do |x|
|
530
|
+
x._read simple_eval_string
|
531
|
+
end
|
532
|
+
c.echo { |x| x._read simple_eval_string }
|
533
|
+
c.foxtrot true
|
534
|
+
end
|
535
|
+
nested_configuration_example conf
|
536
|
+
end
|
608
537
|
|
609
|
-
|
610
|
-
|
611
|
-
|
612
|
-
|
613
|
-
|
614
|
-
bravo do
|
615
|
-
charlie true
|
616
|
-
delta do
|
617
|
-
echo true
|
618
|
-
end
|
538
|
+
it 'settings into a nested configuration from a file (StringIO)' do
|
539
|
+
conf = Configuration.new do |c|
|
540
|
+
c.alpha true
|
541
|
+
c.bravo do |x|
|
542
|
+
x._load StringIO.new simple_eval_string
|
619
543
|
end
|
544
|
+
c.echo { |x| x._load StringIO.new simple_eval_string }
|
545
|
+
c.foxtrot true
|
620
546
|
end
|
621
|
-
|
622
|
-
|
623
|
-
conf.alpha.should be_true
|
624
|
-
conf.bravo.should be_a Configuration
|
625
|
-
conf.bravo.alpha should be_true
|
626
|
-
conf.bravo.charlie should be_true
|
627
|
-
conf.bravo.delta.should be_a Configuration
|
628
|
-
conf.bravo.delta.alpha.should be_true
|
629
|
-
conf.bravo.delta.charlie.should be_true
|
630
|
-
conf.bravo.delta.echo.should be_true
|
631
|
-
end
|
547
|
+
nested_configuration_example conf
|
548
|
+
end
|
632
549
|
|
633
|
-
|
634
|
-
|
635
|
-
|
636
|
-
conf = Configuration.new { |c1| c1.alpha true ; c1.bravo { |c2| c2.charlie true ; c2.delta { |c3| c3.echo true } } }
|
637
|
-
end.to_not raise_error
|
638
|
-
conf.should_not be_nil
|
639
|
-
conf.alpha.should be_true
|
640
|
-
conf.bravo.should be_a Configuration
|
641
|
-
conf.bravo.alpha should be_true
|
642
|
-
conf.bravo.charlie should be_true
|
643
|
-
conf.bravo.delta.should be_a Configuration
|
644
|
-
conf.bravo.delta.alpha.should be_true
|
645
|
-
conf.bravo.delta.charlie.should be_true
|
646
|
-
conf.bravo.delta.echo.should be_true
|
647
|
-
end
|
550
|
+
end # can load
|
551
|
+
|
552
|
+
end # yield DSL
|
648
553
|
|
649
|
-
|
554
|
+
context 'instance_eval DSL' do
|
555
|
+
|
556
|
+
it 'accepts settings without =' do
|
650
557
|
conf = nil
|
651
558
|
expect do
|
652
559
|
conf = Configuration.new do
|
653
|
-
alpha
|
654
|
-
hotel alpha
|
655
|
-
bravo do
|
656
|
-
charlie true
|
657
|
-
foxtrot alpha
|
658
|
-
delta do
|
659
|
-
echo true
|
660
|
-
golf alpha
|
661
|
-
end
|
662
|
-
end
|
560
|
+
alpha :value
|
663
561
|
end
|
664
562
|
end.to_not raise_error
|
665
563
|
conf.should_not be_nil
|
666
|
-
conf.alpha.should
|
667
|
-
conf.bravo.should be_a Configuration
|
668
|
-
conf.bravo.alpha should be_true
|
669
|
-
conf.bravo.charlie should be_true
|
670
|
-
conf.bravo.delta.should be_a Configuration
|
671
|
-
conf.bravo.delta.alpha.should be_true
|
672
|
-
conf.bravo.delta.charlie.should be_true
|
673
|
-
conf.bravo.delta.echo.should be_true
|
674
|
-
conf.bravo.delta.golf.should be_true
|
675
|
-
conf.bravo.foxtrot.should be_true
|
676
|
-
conf.hotel.should be_true
|
564
|
+
conf.alpha.should == :value
|
677
565
|
end
|
678
566
|
|
679
|
-
|
680
|
-
|
681
|
-
context 'dynamic setting' do
|
682
|
-
|
683
|
-
it 'name can be a local' do
|
684
|
-
conf = nil
|
567
|
+
it 'sets local variables with =' do
|
568
|
+
conf = alpha = nil
|
685
569
|
expect do
|
570
|
+
alpha = nil
|
686
571
|
conf = Configuration.new do
|
687
|
-
alpha
|
688
|
-
|
689
|
-
self[local1] = true
|
690
|
-
local2 = 'charlie'
|
691
|
-
self[local2] = true
|
572
|
+
alpha = :value
|
573
|
+
bravo alpha
|
692
574
|
end
|
693
575
|
end.to_not raise_error
|
694
576
|
conf.should_not be_nil
|
695
|
-
conf.alpha.should
|
696
|
-
conf.bravo.should
|
697
|
-
|
577
|
+
conf.alpha.should be_nil
|
578
|
+
conf.bravo.should == :value
|
579
|
+
alpha.should == :value # local alpha set by matching variables
|
698
580
|
end
|
699
581
|
|
700
|
-
it '
|
582
|
+
it 'can refer to an existing setting' do
|
701
583
|
conf = nil
|
702
584
|
expect do
|
703
585
|
conf = Configuration.new do
|
704
|
-
alpha
|
705
|
-
|
706
|
-
|
707
|
-
setting2 'charlie'
|
708
|
-
self[setting2] = true
|
586
|
+
alpha :value
|
587
|
+
bravo alpha
|
588
|
+
charlie bravo
|
709
589
|
end
|
710
590
|
end.to_not raise_error
|
711
591
|
conf.should_not be_nil
|
712
|
-
conf.alpha.should
|
713
|
-
conf.bravo.should
|
714
|
-
conf.charlie.should
|
715
|
-
conf.setting1.should == 'bravo'
|
716
|
-
conf.setting2.should == 'charlie'
|
592
|
+
conf.alpha.should == :value
|
593
|
+
conf.bravo.should == :value
|
594
|
+
conf.charlie.should == :value
|
717
595
|
end
|
718
596
|
|
719
|
-
it '
|
597
|
+
it 'returns value when creating/changing a setting' do
|
720
598
|
conf = nil
|
721
599
|
expect do
|
722
600
|
conf = Configuration.new do
|
723
|
-
alpha
|
724
|
-
local = :bravo
|
725
|
-
self[local] = Configuration.new do
|
726
|
-
charlie true
|
727
|
-
end
|
601
|
+
bravo alpha :value
|
728
602
|
end
|
729
603
|
end.to_not raise_error
|
730
604
|
conf.should_not be_nil
|
731
|
-
conf.alpha.should
|
732
|
-
conf.bravo.should
|
733
|
-
conf.bravo.alpha should be_true
|
734
|
-
conf.bravo.charlie should be_true
|
605
|
+
conf.alpha.should == :value
|
606
|
+
conf.bravo.should == :value
|
735
607
|
end
|
736
608
|
|
737
|
-
|
609
|
+
context 'nested configuration' do
|
610
|
+
|
611
|
+
it 'supported via do..end' do
|
612
|
+
conf = nil
|
613
|
+
expect do
|
614
|
+
conf = Configuration.new do
|
615
|
+
alpha true
|
616
|
+
bravo do
|
617
|
+
charlie true
|
618
|
+
delta do
|
619
|
+
echo true
|
620
|
+
end
|
621
|
+
end
|
622
|
+
end
|
623
|
+
end.to_not raise_error
|
624
|
+
conf.should_not be_nil
|
625
|
+
conf.alpha.should be_true
|
626
|
+
conf.bravo.should be_a Configuration
|
627
|
+
conf.bravo.alpha should be_true
|
628
|
+
conf.bravo.charlie should be_true
|
629
|
+
conf.bravo.delta.should be_a Configuration
|
630
|
+
conf.bravo.delta.alpha.should be_true
|
631
|
+
conf.bravo.delta.charlie.should be_true
|
632
|
+
conf.bravo.delta.echo.should be_true
|
633
|
+
end
|
738
634
|
|
739
|
-
|
635
|
+
it 'supported via {..}' do
|
636
|
+
conf = nil
|
637
|
+
expect do
|
638
|
+
conf = Configuration.new { |c1| c1.alpha true ; c1.bravo { |c2| c2.charlie true ; c2.delta { |c3| c3.echo true } } }
|
639
|
+
end.to_not raise_error
|
640
|
+
conf.should_not be_nil
|
641
|
+
conf.alpha.should be_true
|
642
|
+
conf.bravo.should be_a Configuration
|
643
|
+
conf.bravo.alpha should be_true
|
644
|
+
conf.bravo.charlie should be_true
|
645
|
+
conf.bravo.delta.should be_a Configuration
|
646
|
+
conf.bravo.delta.alpha.should be_true
|
647
|
+
conf.bravo.delta.charlie.should be_true
|
648
|
+
conf.bravo.delta.echo.should be_true
|
649
|
+
end
|
740
650
|
|
741
|
-
|
742
|
-
|
743
|
-
|
744
|
-
|
745
|
-
|
651
|
+
it 'can refer to an inherited setting' do
|
652
|
+
conf = nil
|
653
|
+
expect do
|
654
|
+
conf = Configuration.new do
|
655
|
+
alpha true
|
656
|
+
hotel alpha
|
657
|
+
bravo do
|
658
|
+
charlie true
|
659
|
+
foxtrot alpha
|
660
|
+
delta do
|
661
|
+
echo true
|
662
|
+
golf alpha
|
663
|
+
end
|
664
|
+
end
|
665
|
+
end
|
666
|
+
end.to_not raise_error
|
667
|
+
conf.should_not be_nil
|
668
|
+
conf.alpha.should be_true
|
669
|
+
conf.bravo.should be_a Configuration
|
670
|
+
conf.bravo.alpha should be_true
|
671
|
+
conf.bravo.charlie should be_true
|
672
|
+
conf.bravo.delta.should be_a Configuration
|
673
|
+
conf.bravo.delta.alpha.should be_true
|
674
|
+
conf.bravo.delta.charlie.should be_true
|
675
|
+
conf.bravo.delta.echo.should be_true
|
676
|
+
conf.bravo.delta.golf.should be_true
|
677
|
+
conf.bravo.foxtrot.should be_true
|
678
|
+
conf.hotel.should be_true
|
746
679
|
end
|
747
|
-
simple_configuration_example conf
|
748
|
-
end
|
749
680
|
|
750
|
-
|
751
|
-
|
752
|
-
|
753
|
-
|
754
|
-
|
681
|
+
end # nested configuration
|
682
|
+
|
683
|
+
context 'dynamic setting' do
|
684
|
+
|
685
|
+
it 'name can be a local' do
|
686
|
+
conf = nil
|
687
|
+
expect do
|
688
|
+
conf = Configuration.new do
|
689
|
+
alpha true
|
690
|
+
local1 = 'bravo'
|
691
|
+
self[local1] = true
|
692
|
+
local2 = 'charlie'
|
693
|
+
self[local2] = true
|
694
|
+
end
|
695
|
+
end.to_not raise_error
|
696
|
+
conf.should_not be_nil
|
697
|
+
conf.alpha.should be_true
|
698
|
+
conf.bravo.should be_true
|
699
|
+
conf.charlie.should be_true
|
755
700
|
end
|
756
|
-
simple_configuration_example conf
|
757
|
-
end
|
758
701
|
|
759
|
-
|
760
|
-
|
761
|
-
|
762
|
-
|
763
|
-
|
702
|
+
it 'name can be a setting' do
|
703
|
+
conf = nil
|
704
|
+
expect do
|
705
|
+
conf = Configuration.new do
|
706
|
+
alpha true
|
707
|
+
setting1 'bravo'
|
708
|
+
self[setting1] = true
|
709
|
+
setting2 'charlie'
|
710
|
+
self[setting2] = true
|
711
|
+
end
|
712
|
+
end.to_not raise_error
|
713
|
+
conf.should_not be_nil
|
714
|
+
conf.alpha.should be_true
|
715
|
+
conf.bravo.should be_true
|
716
|
+
conf.charlie.should be_true
|
717
|
+
conf.setting1.should == 'bravo'
|
718
|
+
conf.setting2.should == 'charlie'
|
719
|
+
end
|
720
|
+
|
721
|
+
it 'can reference a nested configuration' do
|
722
|
+
conf = nil
|
723
|
+
expect do
|
724
|
+
conf = Configuration.new do
|
725
|
+
alpha true
|
726
|
+
local = :bravo
|
727
|
+
self[local] = Configuration.new do
|
728
|
+
charlie true
|
729
|
+
end
|
730
|
+
end
|
731
|
+
end.to_not raise_error
|
732
|
+
conf.should_not be_nil
|
733
|
+
conf.alpha.should be_true
|
734
|
+
conf.bravo.should be_a Configuration
|
735
|
+
conf.bravo.alpha should be_true
|
736
|
+
conf.bravo.charlie should be_true
|
737
|
+
end
|
738
|
+
|
739
|
+
end # dynamic setting
|
740
|
+
|
741
|
+
context 'can load' do
|
742
|
+
|
743
|
+
it 'settings into the current configuration from a string' do
|
744
|
+
$simple_eval_string = simple_eval_string
|
745
|
+
conf = Configuration.new do
|
746
|
+
alpha true
|
764
747
|
_read $simple_eval_string
|
765
748
|
end
|
766
|
-
|
767
|
-
foxtrot true
|
749
|
+
simple_configuration_example conf
|
768
750
|
end
|
769
|
-
nested_configuration_example conf
|
770
|
-
end
|
771
751
|
|
772
|
-
|
773
|
-
|
774
|
-
|
775
|
-
|
752
|
+
it 'settings into the current configuration from a file (StringIO)' do
|
753
|
+
$simple_eval_string = simple_eval_string
|
754
|
+
conf = Configuration.new do
|
755
|
+
alpha true
|
776
756
|
_load StringIO.new $simple_eval_string
|
777
757
|
end
|
778
|
-
|
779
|
-
|
758
|
+
simple_configuration_example conf
|
759
|
+
end
|
760
|
+
|
761
|
+
it 'settings into a nested configuration from a string' do
|
762
|
+
$simple_eval_string = simple_eval_string
|
763
|
+
conf = Configuration.new do
|
764
|
+
alpha true
|
765
|
+
bravo do
|
766
|
+
_read $simple_eval_string
|
767
|
+
end
|
768
|
+
echo { _read $simple_eval_string }
|
769
|
+
foxtrot true
|
770
|
+
end
|
771
|
+
nested_configuration_example conf
|
780
772
|
end
|
781
|
-
nested_configuration_example conf
|
782
|
-
end
|
783
773
|
|
784
|
-
|
774
|
+
it 'settings into a nested configuration from a file (StringIO)' do
|
775
|
+
conf = Configuration.new do
|
776
|
+
alpha true
|
777
|
+
bravo do
|
778
|
+
_load StringIO.new $simple_eval_string
|
779
|
+
end
|
780
|
+
echo { _load StringIO.new $simple_eval_string }
|
781
|
+
foxtrot true
|
782
|
+
end
|
783
|
+
nested_configuration_example conf
|
784
|
+
end
|
785
785
|
|
786
|
-
|
786
|
+
end # can load
|
787
787
|
|
788
|
-
|
788
|
+
end # instance_eval DSL
|
789
789
|
|
790
|
-
|
790
|
+
end # mode of usage
|
791
791
|
|
792
|
-
|
793
|
-
orig = simple_explicit_configuration
|
794
|
-
orig.echo :original1
|
795
|
-
orig.foxtrot :original2
|
796
|
-
other = Configuration.new do
|
797
|
-
foxtrot :overridden
|
798
|
-
hotel :new
|
799
|
-
end
|
800
|
-
conf = orig._merge! other
|
801
|
-
simple_configuration_example conf
|
802
|
-
conf.echo.should be :original1
|
803
|
-
conf.hotel.should be :new
|
804
|
-
conf.foxtrot.should be :overridden
|
805
|
-
conf.__send__(:_parent).should be nil
|
806
|
-
conf.should be orig
|
807
|
-
end
|
792
|
+
context 'merge' do
|
808
793
|
|
809
|
-
|
810
|
-
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
|
818
|
-
|
819
|
-
|
820
|
-
|
821
|
-
|
822
|
-
|
823
|
-
|
824
|
-
|
794
|
+
it 'updates its own configuration' do
|
795
|
+
orig = simple_explicit_configuration
|
796
|
+
orig.echo :original1
|
797
|
+
orig.foxtrot :original2
|
798
|
+
other = Configuration.new do
|
799
|
+
foxtrot :overridden
|
800
|
+
hotel :new
|
801
|
+
end
|
802
|
+
conf = orig._merge! other
|
803
|
+
simple_configuration_example conf
|
804
|
+
conf.echo.should be :original1
|
805
|
+
conf.hotel.should be :new
|
806
|
+
conf.foxtrot.should be :overridden
|
807
|
+
conf.__send__(:_parent).should be nil
|
808
|
+
conf.should be orig
|
809
|
+
end
|
825
810
|
|
826
|
-
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
|
833
|
-
nested do
|
834
|
-
golf :also_new
|
835
|
-
hotel :overridden
|
836
|
-
echo :overridden
|
811
|
+
it 'creates a new configuration' do
|
812
|
+
orig = simple_explicit_configuration
|
813
|
+
orig.echo :original1
|
814
|
+
orig.foxtrot :original2
|
815
|
+
other = Configuration.new do
|
816
|
+
foxtrot :overridden
|
817
|
+
hotel :new
|
837
818
|
end
|
838
|
-
|
839
|
-
|
840
|
-
|
841
|
-
|
842
|
-
|
843
|
-
|
844
|
-
|
845
|
-
|
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
|
819
|
+
conf = orig._merge other
|
820
|
+
simple_configuration_example conf
|
821
|
+
conf.echo.should be :original1
|
822
|
+
conf.hotel.should be :new
|
823
|
+
conf.foxtrot.should be :overridden
|
824
|
+
conf.__send__(:_parent).should be nil
|
825
|
+
conf.should_not be orig
|
826
|
+
end
|
853
827
|
|
854
|
-
|
855
|
-
|
856
|
-
|
857
|
-
|
858
|
-
|
859
|
-
|
860
|
-
|
861
|
-
|
862
|
-
|
863
|
-
|
864
|
-
|
828
|
+
it 'updates with a nested configuration' do
|
829
|
+
orig = simple_explicit_configuration
|
830
|
+
orig.echo :original1
|
831
|
+
orig.foxtrot :original2
|
832
|
+
other = Configuration.new do
|
833
|
+
foxtrot :overridden
|
834
|
+
hotel :new
|
835
|
+
nested do
|
836
|
+
golf :also_new
|
837
|
+
hotel :overridden
|
838
|
+
echo :overridden
|
839
|
+
end
|
865
840
|
end
|
866
|
-
|
867
|
-
|
868
|
-
|
869
|
-
|
870
|
-
|
871
|
-
|
872
|
-
|
873
|
-
|
874
|
-
|
875
|
-
|
876
|
-
|
877
|
-
|
878
|
-
|
879
|
-
|
841
|
+
conf = orig._merge! other
|
842
|
+
simple_configuration_example conf
|
843
|
+
conf.echo.should be :original1
|
844
|
+
conf.hotel.should be :new
|
845
|
+
conf.foxtrot.should be :overridden
|
846
|
+
conf.nested.alpha.should be 1
|
847
|
+
conf.nested.echo.should be :overridden
|
848
|
+
conf.nested.foxtrot.should be :overridden
|
849
|
+
conf.nested.golf.should be :also_new
|
850
|
+
conf.nested.hotel.should be :overridden
|
851
|
+
conf.nested.__send__(:_parent).should be conf
|
852
|
+
conf.__send__(:_parent).should be nil
|
853
|
+
conf.should be orig
|
854
|
+
end
|
855
|
+
|
856
|
+
it 'creates with a nested configuration' do
|
857
|
+
orig = simple_explicit_configuration
|
858
|
+
orig.echo :original1
|
859
|
+
orig.foxtrot :original2
|
860
|
+
other = Configuration.new do
|
861
|
+
foxtrot :overridden
|
862
|
+
hotel :new
|
863
|
+
nested do
|
864
|
+
golf :also_new
|
865
|
+
hotel :overridden
|
866
|
+
echo :overridden
|
867
|
+
end
|
868
|
+
end
|
869
|
+
conf = orig._merge other
|
870
|
+
simple_configuration_example conf
|
871
|
+
conf.echo.should be :original1
|
872
|
+
conf.hotel.should be :new
|
873
|
+
conf.foxtrot.should be :overridden
|
874
|
+
conf.nested.alpha.should be 1
|
875
|
+
conf.nested.echo.should be :overridden
|
876
|
+
conf.nested.foxtrot.should be :overridden
|
877
|
+
conf.nested.golf.should be :also_new
|
878
|
+
conf.nested.hotel.should be :overridden
|
879
|
+
conf.nested.__send__(:_parent).should be conf
|
880
|
+
conf.__send__(:_parent).should be nil
|
881
|
+
conf.should_not be orig
|
882
|
+
end
|
883
|
+
|
884
|
+
it 'updates by recursively merging conflicting nested configurations' do
|
885
|
+
orig = simple_explicit_configuration
|
886
|
+
orig.nested1 = Configuration.new do
|
887
|
+
echo :original
|
888
|
+
foxtrot :original
|
889
|
+
nested2 do
|
890
|
+
golf :original
|
891
|
+
hotel :original
|
892
|
+
end
|
893
|
+
end
|
894
|
+
other = Configuration.new do
|
895
|
+
nested1 do
|
896
|
+
echo :replaced
|
897
|
+
india :new
|
898
|
+
nested2 do
|
899
|
+
golf :replaced
|
900
|
+
juliet :new
|
901
|
+
end
|
902
|
+
end
|
903
|
+
end
|
904
|
+
conf = orig._merge! other
|
905
|
+
simple_configuration_example conf
|
906
|
+
conf.nested1.echo.should be :replaced
|
907
|
+
conf.nested1.foxtrot.should be :original
|
908
|
+
conf.nested1.india.should be :new
|
909
|
+
conf.nested1.nested2.golf.should be :replaced
|
910
|
+
conf.nested1.nested2.hotel.should be :original
|
911
|
+
conf.nested1.nested2.juliet.should be :new
|
912
|
+
conf.nested1.__send__(:_parent).should be conf
|
913
|
+
conf.__send__(:_parent).should be nil
|
914
|
+
conf.should be orig
|
915
|
+
end
|
916
|
+
|
917
|
+
it 'creates by recursively merging conflicting nested configurations' do
|
918
|
+
orig = simple_explicit_configuration
|
919
|
+
orig.nested1 = Configuration.new do
|
920
|
+
echo :original
|
921
|
+
foxtrot :original
|
922
|
+
nested2 do
|
923
|
+
golf :original
|
924
|
+
hotel :original
|
925
|
+
end
|
926
|
+
end
|
927
|
+
other = Configuration.new do
|
928
|
+
nested1 do
|
929
|
+
echo :replaced
|
930
|
+
india :new
|
931
|
+
nested2 do
|
932
|
+
golf :replaced
|
933
|
+
juliet :new
|
934
|
+
end
|
935
|
+
end
|
936
|
+
end
|
937
|
+
conf = orig._merge other
|
938
|
+
simple_configuration_example conf
|
939
|
+
conf.nested1.echo.should be :replaced
|
940
|
+
conf.nested1.foxtrot.should be :original
|
941
|
+
conf.nested1.india.should be :new
|
942
|
+
conf.nested1.nested2.golf.should be :replaced
|
943
|
+
conf.nested1.nested2.hotel.should be :original
|
944
|
+
conf.nested1.nested2.juliet.should be :new
|
945
|
+
conf.nested1.__send__(:_parent).should be conf
|
946
|
+
conf.__send__(:_parent).should be nil
|
947
|
+
conf.should_not be orig
|
948
|
+
end
|
949
|
+
|
880
950
|
end
|
881
951
|
|
882
|
-
end
|
952
|
+
end # "v1.0"
|
953
|
+
|
954
|
+
#context 'v1.1' do
|
955
|
+
#
|
956
|
+
# context 'merge' do
|
957
|
+
#
|
958
|
+
# end
|
959
|
+
#
|
960
|
+
#end #v1.1
|
883
961
|
|
884
962
|
end
|
885
963
|
|