configatron 2.1.5 → 2.1.6
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/doc/classes/Configatron.html +2 -1
- data/doc/classes/Configatron/ProtectedParameter.html +6 -6
- data/doc/classes/Configatron/Store.html +172 -63
- data/doc/classes/Kernel.html +6 -6
- data/doc/created.rid +1 -1
- data/doc/files/lib/configatron/errors_rb.html +1 -1
- data/doc/files/lib/configatron/store_rb.html +1 -1
- data/doc/fr_class_index.html +1 -0
- data/doc/fr_method_index.html +8 -3
- data/lib/configatron/errors.rb +7 -1
- data/lib/configatron/store.rb +28 -2
- data/spec/lib/configatron_spec.rb +51 -0
- metadata +3 -3
@@ -119,7 +119,8 @@
|
|
119
119
|
<div id="class-list">
|
120
120
|
<h3 class="section-bar">Classes and Modules</h3>
|
121
121
|
|
122
|
-
Class <a href="Configatron/
|
122
|
+
Class <a href="Configatron/LockedNamespace.html" class="link">Configatron::LockedNamespace</a><br />
|
123
|
+
Class <a href="Configatron/ProtectedParameter.html" class="link">Configatron::ProtectedParameter</a><br />
|
123
124
|
Class <a href="Configatron/Store.html" class="link">Configatron::Store</a><br />
|
124
125
|
|
125
126
|
</div>
|
@@ -86,7 +86,7 @@
|
|
86
86
|
<h3 class="section-bar">Methods</h3>
|
87
87
|
|
88
88
|
<div class="name-list">
|
89
|
-
<a href="#
|
89
|
+
<a href="#M000025">intialize</a>
|
90
90
|
</div>
|
91
91
|
</div>
|
92
92
|
|
@@ -108,19 +108,19 @@
|
|
108
108
|
<div id="methods">
|
109
109
|
<h3 class="section-bar">Public Instance methods</h3>
|
110
110
|
|
111
|
-
<div id="method-
|
112
|
-
<a name="
|
111
|
+
<div id="method-M000025" class="method-detail">
|
112
|
+
<a name="M000025"></a>
|
113
113
|
|
114
114
|
<div class="method-heading">
|
115
|
-
<a href="#
|
115
|
+
<a href="#M000025" class="method-signature">
|
116
116
|
<span class="method-name">intialize</span><span class="method-args">(name)</span>
|
117
117
|
</a>
|
118
118
|
</div>
|
119
119
|
|
120
120
|
<div class="method-description">
|
121
121
|
<p><a class="source-toggle" href="#"
|
122
|
-
onclick="toggleCode('
|
123
|
-
<div class="method-source-code" id="
|
122
|
+
onclick="toggleCode('M000025-source');return false;">[Source]</a></p>
|
123
|
+
<div class="method-source-code" id="M000025-source">
|
124
124
|
<pre>
|
125
125
|
<span class="ruby-comment cmt"># File lib/configatron/errors.rb, line 3</span>
|
126
126
|
3: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">intialize</span>(<span class="ruby-identifier">name</span>)
|
@@ -88,8 +88,10 @@
|
|
88
88
|
<div class="name-list">
|
89
89
|
<a href="#M000009">configure_from_hash</a>
|
90
90
|
<a href="#M000010">configure_from_yaml</a>
|
91
|
-
<a href="#
|
91
|
+
<a href="#M000021">deep_clone</a>
|
92
92
|
<a href="#M000008">inspect</a>
|
93
|
+
<a href="#M000019">lock</a>
|
94
|
+
<a href="#M000022">lock!</a>
|
93
95
|
<a href="#M000006">new</a>
|
94
96
|
<a href="#M000011">nil?</a>
|
95
97
|
<a href="#M000015">protect</a>
|
@@ -98,6 +100,8 @@
|
|
98
100
|
<a href="#M000012">retrieve</a>
|
99
101
|
<a href="#M000014">set_default</a>
|
100
102
|
<a href="#M000007">to_hash</a>
|
103
|
+
<a href="#M000020">unlock</a>
|
104
|
+
<a href="#M000023">unlock!</a>
|
101
105
|
<a href="#M000017">unprotect</a>
|
102
106
|
<a href="#M000018">unprotect_all!</a>
|
103
107
|
</div>
|
@@ -213,11 +217,11 @@ indicates a specific hash that should be loaded from the file.
|
|
213
217
|
</div>
|
214
218
|
</div>
|
215
219
|
|
216
|
-
<div id="method-
|
217
|
-
<a name="
|
220
|
+
<div id="method-M000021" class="method-detail">
|
221
|
+
<a name="M000021"></a>
|
218
222
|
|
219
223
|
<div class="method-heading">
|
220
|
-
<a href="#
|
224
|
+
<a href="#M000021" class="method-signature">
|
221
225
|
<span class="method-name">deep_clone</span><span class="method-args">( obj=self, cloned={} )</span>
|
222
226
|
</a>
|
223
227
|
</div>
|
@@ -265,41 +269,41 @@ href="http://simplypowerful.1984.cz/goodlibs/1.2006.05.23">simplypowerful.1984.c
|
|
265
269
|
either the dual license version in 2003, or any later version.
|
266
270
|
</pre>
|
267
271
|
<p><a class="source-toggle" href="#"
|
268
|
-
onclick="toggleCode('
|
269
|
-
<div class="method-source-code" id="
|
272
|
+
onclick="toggleCode('M000021-source');return false;">[Source]</a></p>
|
273
|
+
<div class="method-source-code" id="M000021-source">
|
270
274
|
<pre>
|
271
|
-
<span class="ruby-comment cmt"># File lib/configatron/store.rb, line
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
275
|
+
<span class="ruby-comment cmt"># File lib/configatron/store.rb, line 191</span>
|
276
|
+
191: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">deep_clone</span>( <span class="ruby-identifier">obj</span>=<span class="ruby-keyword kw">self</span>, <span class="ruby-identifier">cloned</span>={} )
|
277
|
+
192: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">cloned</span>.<span class="ruby-identifier">has_key?</span>( <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">object_id</span> )
|
278
|
+
193: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">cloned</span>[<span class="ruby-identifier">obj</span>.<span class="ruby-identifier">object_id</span>]
|
279
|
+
194: <span class="ruby-keyword kw">else</span>
|
280
|
+
195: <span class="ruby-keyword kw">begin</span>
|
281
|
+
196: <span class="ruby-identifier">cl</span> = <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">clone</span>
|
282
|
+
197: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span>
|
283
|
+
198: <span class="ruby-comment cmt"># unclonnable (TrueClass, Fixnum, ...)</span>
|
284
|
+
199: <span class="ruby-identifier">cloned</span>[<span class="ruby-identifier">obj</span>.<span class="ruby-identifier">object_id</span>] = <span class="ruby-identifier">obj</span>
|
285
|
+
200: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">obj</span>
|
286
|
+
201: <span class="ruby-keyword kw">else</span>
|
287
|
+
202: <span class="ruby-identifier">cloned</span>[<span class="ruby-identifier">obj</span>.<span class="ruby-identifier">object_id</span>] = <span class="ruby-identifier">cl</span>
|
288
|
+
203: <span class="ruby-identifier">cloned</span>[<span class="ruby-identifier">cl</span>.<span class="ruby-identifier">object_id</span>] = <span class="ruby-identifier">cl</span>
|
289
|
+
204: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">cl</span>.<span class="ruby-identifier">is_a?</span>( <span class="ruby-constant">Hash</span> )
|
290
|
+
205: <span class="ruby-identifier">cl</span>.<span class="ruby-identifier">clone</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">k</span>,<span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
|
291
|
+
206: <span class="ruby-identifier">cl</span>[<span class="ruby-identifier">k</span>] = <span class="ruby-identifier">deep_clone</span>( <span class="ruby-identifier">v</span>, <span class="ruby-identifier">cloned</span> )
|
292
|
+
207: }
|
293
|
+
208: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">cl</span>.<span class="ruby-identifier">is_a?</span>( <span class="ruby-constant">Array</span> )
|
294
|
+
209: <span class="ruby-identifier">cl</span>.<span class="ruby-identifier">collect!</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">v</span><span class="ruby-operator">|</span>
|
295
|
+
210: <span class="ruby-identifier">deep_clone</span>( <span class="ruby-identifier">v</span>, <span class="ruby-identifier">cloned</span> )
|
296
|
+
211: }
|
297
|
+
212: <span class="ruby-keyword kw">end</span>
|
298
|
+
213: <span class="ruby-identifier">cl</span>.<span class="ruby-identifier">instance_variables</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">var</span><span class="ruby-operator">|</span>
|
299
|
+
214: <span class="ruby-identifier">v</span> = <span class="ruby-identifier">cl</span>.<span class="ruby-identifier">instance_eval</span>( <span class="ruby-identifier">var</span> )
|
300
|
+
215: <span class="ruby-identifier">v_cl</span> = <span class="ruby-identifier">deep_clone</span>( <span class="ruby-identifier">v</span>, <span class="ruby-identifier">cloned</span> )
|
301
|
+
216: <span class="ruby-identifier">cl</span>.<span class="ruby-identifier">instance_eval</span>( <span class="ruby-node">"#{var} = v_cl"</span> )
|
302
|
+
217: <span class="ruby-keyword kw">end</span>
|
303
|
+
218: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">cl</span>
|
304
|
+
219: <span class="ruby-keyword kw">end</span>
|
305
|
+
220: <span class="ruby-keyword kw">end</span>
|
306
|
+
221: <span class="ruby-keyword kw">end</span>
|
303
307
|
</pre>
|
304
308
|
</div>
|
305
309
|
</div>
|
@@ -355,6 +359,36 @@ href="http://simplypowerful.1984.cz/goodlibs/1.2006.05.23">simplypowerful.1984.c
|
|
355
359
|
</div>
|
356
360
|
</div>
|
357
361
|
|
362
|
+
<div id="method-M000019" class="method-detail">
|
363
|
+
<a name="M000019"></a>
|
364
|
+
|
365
|
+
<div class="method-heading">
|
366
|
+
<a href="#M000019" class="method-signature">
|
367
|
+
<span class="method-name">lock</span><span class="method-args">(name)</span>
|
368
|
+
</a>
|
369
|
+
</div>
|
370
|
+
|
371
|
+
<div class="method-description">
|
372
|
+
<p>
|
373
|
+
Prevents a namespace from having <a href="Store.html#M000006">new</a>
|
374
|
+
parameters set. The <a href="Store.html#M000019">lock</a> is applied
|
375
|
+
recursively to any namespaces below it.
|
376
|
+
</p>
|
377
|
+
<p><a class="source-toggle" href="#"
|
378
|
+
onclick="toggleCode('M000019-source');return false;">[Source]</a></p>
|
379
|
+
<div class="method-source-code" id="M000019-source">
|
380
|
+
<pre>
|
381
|
+
<span class="ruby-comment cmt"># File lib/configatron/store.rb, line 143</span>
|
382
|
+
143: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">lock</span>(<span class="ruby-identifier">name</span>)
|
383
|
+
144: <span class="ruby-identifier">namespace</span> = <span class="ruby-ivar">@_store</span>[<span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_sym</span>]
|
384
|
+
145: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">"Namespace #{name.inspect} does not exist"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">namespace</span>.<span class="ruby-identifier">nil?</span>
|
385
|
+
146: <span class="ruby-identifier">namespace</span>.<span class="ruby-identifier">lock!</span>
|
386
|
+
147: <span class="ruby-keyword kw">end</span>
|
387
|
+
</pre>
|
388
|
+
</div>
|
389
|
+
</div>
|
390
|
+
</div>
|
391
|
+
|
358
392
|
<div id="method-M000011" class="method-detail">
|
359
393
|
<a name="M000011"></a>
|
360
394
|
|
@@ -400,10 +434,10 @@ well.
|
|
400
434
|
onclick="toggleCode('M000015-source');return false;">[Source]</a></p>
|
401
435
|
<div class="method-source-code" id="M000015-source">
|
402
436
|
<pre>
|
403
|
-
<span class="ruby-comment cmt"># File lib/configatron/store.rb, line
|
404
|
-
|
405
|
-
|
406
|
-
|
437
|
+
<span class="ruby-comment cmt"># File lib/configatron/store.rb, line 114</span>
|
438
|
+
114: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">protect</span>(<span class="ruby-identifier">name</span>)
|
439
|
+
115: <span class="ruby-ivar">@_protected</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_sym</span>
|
440
|
+
116: <span class="ruby-keyword kw">end</span>
|
407
441
|
</pre>
|
408
442
|
</div>
|
409
443
|
</div>
|
@@ -426,15 +460,15 @@ Prevents all parameters from being reassigned.
|
|
426
460
|
onclick="toggleCode('M000016-source');return false;">[Source]</a></p>
|
427
461
|
<div class="method-source-code" id="M000016-source">
|
428
462
|
<pre>
|
429
|
-
<span class="ruby-comment cmt"># File lib/configatron/store.rb, line
|
430
|
-
|
431
|
-
|
432
|
-
|
433
|
-
|
434
|
-
|
435
|
-
|
436
|
-
|
437
|
-
|
463
|
+
<span class="ruby-comment cmt"># File lib/configatron/store.rb, line 119</span>
|
464
|
+
119: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">protect_all!</span>
|
465
|
+
120: <span class="ruby-ivar">@_protected</span>.<span class="ruby-identifier">clear</span>
|
466
|
+
121: <span class="ruby-ivar">@_store</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span><span class="ruby-operator">|</span>
|
467
|
+
122: <span class="ruby-identifier">val</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">k</span>)
|
468
|
+
123: <span class="ruby-identifier">val</span>.<span class="ruby-identifier">protect_all!</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">val</span>.<span class="ruby-identifier">class</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Configatron</span><span class="ruby-operator">::</span><span class="ruby-constant">Store</span>
|
469
|
+
124: <span class="ruby-ivar">@_protected</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">k</span>
|
470
|
+
125: <span class="ruby-keyword kw">end</span>
|
471
|
+
126: <span class="ruby-keyword kw">end</span>
|
438
472
|
</pre>
|
439
473
|
</div>
|
440
474
|
</div>
|
@@ -549,6 +583,31 @@ Returns a Hash representing the configurations
|
|
549
583
|
</div>
|
550
584
|
</div>
|
551
585
|
|
586
|
+
<div id="method-M000020" class="method-detail">
|
587
|
+
<a name="M000020"></a>
|
588
|
+
|
589
|
+
<div class="method-heading">
|
590
|
+
<a href="#M000020" class="method-signature">
|
591
|
+
<span class="method-name">unlock</span><span class="method-args">(name)</span>
|
592
|
+
</a>
|
593
|
+
</div>
|
594
|
+
|
595
|
+
<div class="method-description">
|
596
|
+
<p><a class="source-toggle" href="#"
|
597
|
+
onclick="toggleCode('M000020-source');return false;">[Source]</a></p>
|
598
|
+
<div class="method-source-code" id="M000020-source">
|
599
|
+
<pre>
|
600
|
+
<span class="ruby-comment cmt"># File lib/configatron/store.rb, line 149</span>
|
601
|
+
149: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">unlock</span>(<span class="ruby-identifier">name</span>)
|
602
|
+
150: <span class="ruby-identifier">namespace</span> = <span class="ruby-ivar">@_store</span>[<span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_sym</span>]
|
603
|
+
151: <span class="ruby-identifier">raise</span> <span class="ruby-constant">ArgumentError</span>, <span class="ruby-node">"Namespace #{name.inspect} does not exist"</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">namespace</span>.<span class="ruby-identifier">nil?</span>
|
604
|
+
152: <span class="ruby-identifier">namespace</span>.<span class="ruby-identifier">unlock!</span>
|
605
|
+
153: <span class="ruby-keyword kw">end</span>
|
606
|
+
</pre>
|
607
|
+
</div>
|
608
|
+
</div>
|
609
|
+
</div>
|
610
|
+
|
552
611
|
<div id="method-M000017" class="method-detail">
|
553
612
|
<a name="M000017"></a>
|
554
613
|
|
@@ -566,10 +625,10 @@ Removes the protection of a parameter.
|
|
566
625
|
onclick="toggleCode('M000017-source');return false;">[Source]</a></p>
|
567
626
|
<div class="method-source-code" id="M000017-source">
|
568
627
|
<pre>
|
569
|
-
<span class="ruby-comment cmt"># File lib/configatron/store.rb, line
|
570
|
-
|
571
|
-
|
572
|
-
|
628
|
+
<span class="ruby-comment cmt"># File lib/configatron/store.rb, line 129</span>
|
629
|
+
129: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">unprotect</span>(<span class="ruby-identifier">name</span>)
|
630
|
+
130: <span class="ruby-ivar">@_protected</span>.<span class="ruby-identifier">reject!</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">e</span><span class="ruby-operator">|</span> <span class="ruby-identifier">e</span> <span class="ruby-operator">==</span> <span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_sym</span> }
|
631
|
+
131: <span class="ruby-keyword kw">end</span>
|
573
632
|
</pre>
|
574
633
|
</div>
|
575
634
|
</div>
|
@@ -589,14 +648,64 @@ Removes the protection of a parameter.
|
|
589
648
|
onclick="toggleCode('M000018-source');return false;">[Source]</a></p>
|
590
649
|
<div class="method-source-code" id="M000018-source">
|
591
650
|
<pre>
|
592
|
-
<span class="ruby-comment cmt"># File lib/configatron/store.rb, line
|
593
|
-
|
594
|
-
|
595
|
-
|
596
|
-
|
597
|
-
|
598
|
-
|
599
|
-
|
651
|
+
<span class="ruby-comment cmt"># File lib/configatron/store.rb, line 133</span>
|
652
|
+
133: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">unprotect_all!</span>
|
653
|
+
134: <span class="ruby-ivar">@_protected</span>.<span class="ruby-identifier">clear</span>
|
654
|
+
135: <span class="ruby-ivar">@_store</span>.<span class="ruby-identifier">keys</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">k</span><span class="ruby-operator">|</span>
|
655
|
+
136: <span class="ruby-identifier">val</span> = <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">k</span>)
|
656
|
+
137: <span class="ruby-identifier">val</span>.<span class="ruby-identifier">unprotect_all!</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">val</span>.<span class="ruby-identifier">class</span> <span class="ruby-operator">==</span> <span class="ruby-constant">Configatron</span><span class="ruby-operator">::</span><span class="ruby-constant">Store</span>
|
657
|
+
138: <span class="ruby-keyword kw">end</span>
|
658
|
+
139: <span class="ruby-keyword kw">end</span>
|
659
|
+
</pre>
|
660
|
+
</div>
|
661
|
+
</div>
|
662
|
+
</div>
|
663
|
+
|
664
|
+
<h3 class="section-bar">Protected Instance methods</h3>
|
665
|
+
|
666
|
+
<div id="method-M000022" class="method-detail">
|
667
|
+
<a name="M000022"></a>
|
668
|
+
|
669
|
+
<div class="method-heading">
|
670
|
+
<a href="#M000022" class="method-signature">
|
671
|
+
<span class="method-name">lock!</span><span class="method-args">()</span>
|
672
|
+
</a>
|
673
|
+
</div>
|
674
|
+
|
675
|
+
<div class="method-description">
|
676
|
+
<p><a class="source-toggle" href="#"
|
677
|
+
onclick="toggleCode('M000022-source');return false;">[Source]</a></p>
|
678
|
+
<div class="method-source-code" id="M000022-source">
|
679
|
+
<pre>
|
680
|
+
<span class="ruby-comment cmt"># File lib/configatron/store.rb, line 224</span>
|
681
|
+
224: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">lock!</span>
|
682
|
+
225: <span class="ruby-ivar">@_locked</span> = <span class="ruby-keyword kw">true</span>
|
683
|
+
226: <span class="ruby-ivar">@_store</span>.<span class="ruby-identifier">values</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">store</span><span class="ruby-operator">|</span> <span class="ruby-identifier">store</span>.<span class="ruby-identifier">lock!</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">store</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Configatron</span><span class="ruby-operator">::</span><span class="ruby-constant">Store</span>) }
|
684
|
+
227: <span class="ruby-keyword kw">end</span>
|
685
|
+
</pre>
|
686
|
+
</div>
|
687
|
+
</div>
|
688
|
+
</div>
|
689
|
+
|
690
|
+
<div id="method-M000023" class="method-detail">
|
691
|
+
<a name="M000023"></a>
|
692
|
+
|
693
|
+
<div class="method-heading">
|
694
|
+
<a href="#M000023" class="method-signature">
|
695
|
+
<span class="method-name">unlock!</span><span class="method-args">()</span>
|
696
|
+
</a>
|
697
|
+
</div>
|
698
|
+
|
699
|
+
<div class="method-description">
|
700
|
+
<p><a class="source-toggle" href="#"
|
701
|
+
onclick="toggleCode('M000023-source');return false;">[Source]</a></p>
|
702
|
+
<div class="method-source-code" id="M000023-source">
|
703
|
+
<pre>
|
704
|
+
<span class="ruby-comment cmt"># File lib/configatron/store.rb, line 229</span>
|
705
|
+
229: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">unlock!</span>
|
706
|
+
230: <span class="ruby-ivar">@_locked</span> = <span class="ruby-keyword kw">false</span>
|
707
|
+
231: <span class="ruby-ivar">@_store</span>.<span class="ruby-identifier">values</span>.<span class="ruby-identifier">each</span> { <span class="ruby-operator">|</span><span class="ruby-identifier">store</span><span class="ruby-operator">|</span> <span class="ruby-identifier">store</span>.<span class="ruby-identifier">unlock!</span> <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">store</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Configatron</span><span class="ruby-operator">::</span><span class="ruby-constant">Store</span>) }
|
708
|
+
232: <span class="ruby-keyword kw">end</span>
|
600
709
|
</pre>
|
601
710
|
</div>
|
602
711
|
</div>
|
data/doc/classes/Kernel.html
CHANGED
@@ -80,7 +80,7 @@
|
|
80
80
|
<h3 class="section-bar">Methods</h3>
|
81
81
|
|
82
82
|
<div class="name-list">
|
83
|
-
<a href="#
|
83
|
+
<a href="#M000026">configatron</a>
|
84
84
|
</div>
|
85
85
|
</div>
|
86
86
|
|
@@ -102,11 +102,11 @@
|
|
102
102
|
<div id="methods">
|
103
103
|
<h3 class="section-bar">Public Instance methods</h3>
|
104
104
|
|
105
|
-
<div id="method-
|
106
|
-
<a name="
|
105
|
+
<div id="method-M000026" class="method-detail">
|
106
|
+
<a name="M000026"></a>
|
107
107
|
|
108
108
|
<div class="method-heading">
|
109
|
-
<a href="#
|
109
|
+
<a href="#M000026" class="method-signature">
|
110
110
|
<span class="method-name">configatron</span><span class="method-args">()</span>
|
111
111
|
</a>
|
112
112
|
</div>
|
@@ -117,8 +117,8 @@ Provides access to the <a href="Configatron.html">Configatron</a> storage
|
|
117
117
|
system.
|
118
118
|
</p>
|
119
119
|
<p><a class="source-toggle" href="#"
|
120
|
-
onclick="toggleCode('
|
121
|
-
<div class="method-source-code" id="
|
120
|
+
onclick="toggleCode('M000026-source');return false;">[Source]</a></p>
|
121
|
+
<div class="method-source-code" id="M000026-source">
|
122
122
|
<pre>
|
123
123
|
<span class="ruby-comment cmt"># File lib/configatron/kernel.rb, line 4</span>
|
124
124
|
4: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">configatron</span>
|
data/doc/created.rid
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
Fri, 21 Nov 2008 19:05:37 -0500
|
data/doc/fr_class_index.html
CHANGED
@@ -21,6 +21,7 @@
|
|
21
21
|
<h1 class="section-bar">Classes</h1>
|
22
22
|
<div id="index-entries">
|
23
23
|
<a href="classes/Configatron.html">Configatron</a><br />
|
24
|
+
<a href="classes/Configatron/LockedNamespace.html">Configatron::LockedNamespace</a><br />
|
24
25
|
<a href="classes/Configatron/ProtectedParameter.html">Configatron::ProtectedParameter</a><br />
|
25
26
|
<a href="classes/Configatron/Store.html">Configatron::Store</a><br />
|
26
27
|
<a href="classes/Kernel.html">Kernel</a><br />
|
data/doc/fr_method_index.html
CHANGED
@@ -20,14 +20,17 @@
|
|
20
20
|
<div id="index">
|
21
21
|
<h1 class="section-bar">Methods</h1>
|
22
22
|
<div id="index-entries">
|
23
|
-
<a href="classes/Kernel.html#
|
23
|
+
<a href="classes/Kernel.html#M000026">configatron (Kernel)</a><br />
|
24
24
|
<a href="classes/Configatron/Store.html#M000009">configure_from_hash (Configatron::Store)</a><br />
|
25
25
|
<a href="classes/Configatron/Store.html#M000010">configure_from_yaml (Configatron::Store)</a><br />
|
26
|
-
<a href="classes/Configatron/Store.html#
|
26
|
+
<a href="classes/Configatron/Store.html#M000021">deep_clone (Configatron::Store)</a><br />
|
27
27
|
<a href="classes/Configatron/Store.html#M000008">inspect (Configatron::Store)</a><br />
|
28
|
-
<a href="classes/Configatron/ProtectedParameter.html#
|
28
|
+
<a href="classes/Configatron/ProtectedParameter.html#M000025">intialize (Configatron::ProtectedParameter)</a><br />
|
29
|
+
<a href="classes/Configatron/Store.html#M000019">lock (Configatron::Store)</a><br />
|
30
|
+
<a href="classes/Configatron/Store.html#M000022">lock! (Configatron::Store)</a><br />
|
29
31
|
<a href="classes/Configatron.html#M000001">method_missing (Configatron)</a><br />
|
30
32
|
<a href="classes/Configatron/Store.html#M000006">new (Configatron::Store)</a><br />
|
33
|
+
<a href="classes/Configatron/LockedNamespace.html#M000024">new (Configatron::LockedNamespace)</a><br />
|
31
34
|
<a href="classes/Configatron/Store.html#M000011">nil? (Configatron::Store)</a><br />
|
32
35
|
<a href="classes/Configatron/Store.html#M000015">protect (Configatron::Store)</a><br />
|
33
36
|
<a href="classes/Configatron/Store.html#M000016">protect_all! (Configatron::Store)</a><br />
|
@@ -39,6 +42,8 @@
|
|
39
42
|
<a href="classes/Configatron.html#M000005">temp_end (Configatron)</a><br />
|
40
43
|
<a href="classes/Configatron.html#M000004">temp_start (Configatron)</a><br />
|
41
44
|
<a href="classes/Configatron/Store.html#M000007">to_hash (Configatron::Store)</a><br />
|
45
|
+
<a href="classes/Configatron/Store.html#M000020">unlock (Configatron::Store)</a><br />
|
46
|
+
<a href="classes/Configatron/Store.html#M000023">unlock! (Configatron::Store)</a><br />
|
42
47
|
<a href="classes/Configatron/Store.html#M000017">unprotect (Configatron::Store)</a><br />
|
43
48
|
<a href="classes/Configatron/Store.html#M000018">unprotect_all! (Configatron::Store)</a><br />
|
44
49
|
</div>
|
data/lib/configatron/errors.rb
CHANGED
data/lib/configatron/store.rb
CHANGED
@@ -94,6 +94,7 @@ class Configatron
|
|
94
94
|
if sym.to_s.match(/(.+)=$/)
|
95
95
|
name = sym.to_s.gsub("=", '').to_sym
|
96
96
|
raise Configatron::ProtectedParameter.new(name) if @_protected.include?(name) || self.methods.include?(name.to_s)
|
97
|
+
raise Configatron::LockedNamespace.new(@_name) if @_locked && !@_store.has_key?(name)
|
97
98
|
@_store[name] = parse_options(*args)
|
98
99
|
elsif @_store.has_key?(sym)
|
99
100
|
return @_store[sym]
|
@@ -113,7 +114,7 @@ class Configatron
|
|
113
114
|
def protect(name)
|
114
115
|
@_protected << name.to_sym
|
115
116
|
end
|
116
|
-
|
117
|
+
|
117
118
|
# Prevents all parameters from being reassigned.
|
118
119
|
def protect_all!
|
119
120
|
@_protected.clear
|
@@ -136,6 +137,20 @@ class Configatron
|
|
136
137
|
val.unprotect_all! if val.class == Configatron::Store
|
137
138
|
end
|
138
139
|
end
|
140
|
+
|
141
|
+
# Prevents a namespace from having new parameters set. The lock is applied
|
142
|
+
# recursively to any namespaces below it.
|
143
|
+
def lock(name)
|
144
|
+
namespace = @_store[name.to_sym]
|
145
|
+
raise ArgumentError, "Namespace #{name.inspect} does not exist" if namespace.nil?
|
146
|
+
namespace.lock!
|
147
|
+
end
|
148
|
+
|
149
|
+
def unlock(name)
|
150
|
+
namespace = @_store[name.to_sym]
|
151
|
+
raise ArgumentError, "Namespace #{name.inspect} does not exist" if namespace.nil?
|
152
|
+
namespace.unlock!
|
153
|
+
end
|
139
154
|
|
140
155
|
# = DeepClone
|
141
156
|
#
|
@@ -205,6 +220,17 @@ class Configatron
|
|
205
220
|
end
|
206
221
|
end
|
207
222
|
|
223
|
+
protected
|
224
|
+
def lock!
|
225
|
+
@_locked = true
|
226
|
+
@_store.values.each { |store| store.lock! if store.is_a?(Configatron::Store) }
|
227
|
+
end
|
228
|
+
|
229
|
+
def unlock!
|
230
|
+
@_locked = false
|
231
|
+
@_store.values.each { |store| store.unlock! if store.is_a?(Configatron::Store) }
|
232
|
+
end
|
233
|
+
|
208
234
|
private
|
209
235
|
def parse_options(options)
|
210
236
|
if options.is_a?(Hash)
|
@@ -221,4 +247,4 @@ class Configatron
|
|
221
247
|
end
|
222
248
|
|
223
249
|
end
|
224
|
-
end
|
250
|
+
end
|
@@ -75,6 +75,57 @@ describe "configatron" do
|
|
75
75
|
end
|
76
76
|
|
77
77
|
end
|
78
|
+
|
79
|
+
describe 'lock' do
|
80
|
+
before :each do
|
81
|
+
configatron.letters.a = 'A'
|
82
|
+
configatron.letters.b = 'B'
|
83
|
+
configatron.letters.greek.alpha = 'alpha'
|
84
|
+
configatron.lock(:letters)
|
85
|
+
end
|
86
|
+
|
87
|
+
it 'should allow setting of existing parameters in locked parameter' do
|
88
|
+
lambda { configatron.letters.a = 'a' }.should_not raise_error
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'should not allow setting of a parameter that is not already set' do
|
92
|
+
lambda { configatron.letters.c = 'C' }.should raise_error(Configatron::LockedNamespace)
|
93
|
+
end
|
94
|
+
|
95
|
+
it 'should allow setting of existing parameters in child of locked parameter' do
|
96
|
+
lambda { configatron.letters.greek.alpha = 'a' }.should_not raise_error
|
97
|
+
end
|
98
|
+
|
99
|
+
it 'should not allow setting of new parameters in child of locked parameter' do
|
100
|
+
lambda { configatron.letters.greek.beta = 'beta' }.should raise_error(Configatron::LockedNamespace)
|
101
|
+
end
|
102
|
+
|
103
|
+
it 'should not affect parameters below the locked namespace' do
|
104
|
+
lambda { configatron.one = 1 }.should_not raise_error
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'should raise an ArgumentError if unknown namespace is locked' do
|
108
|
+
lambda { configatron.lock(:numbers).should raise_error(ArgumentError) }
|
109
|
+
end
|
110
|
+
|
111
|
+
describe 'then unlock' do
|
112
|
+
before :each do
|
113
|
+
configatron.unlock(:letters)
|
114
|
+
end
|
115
|
+
|
116
|
+
it 'should allow setting of new parameter in unlocked namespace' do
|
117
|
+
lambda { configatron.letters.d = 'd' }.should_not raise_error
|
118
|
+
end
|
119
|
+
|
120
|
+
it 'should allow setting of new parameter in unlocked namespace\'s child' do
|
121
|
+
lambda { configatron.letters.greek.zeta = 'z' }.should_not raise_error
|
122
|
+
end
|
123
|
+
|
124
|
+
it 'should raise an ArgumentError if unknown namespace is unlocked' do
|
125
|
+
lambda { configatron.unlock(:numbers).should raise_error(ArgumentError) }
|
126
|
+
end
|
127
|
+
end
|
128
|
+
end
|
78
129
|
|
79
130
|
describe 'temp' do
|
80
131
|
|
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: 2.1.
|
4
|
+
version: 2.1.6
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- markbates
|
@@ -9,7 +9,7 @@ autorequire:
|
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
11
|
|
12
|
-
date: 2008-
|
12
|
+
date: 2008-11-21 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -67,7 +67,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
67
67
|
requirements: []
|
68
68
|
|
69
69
|
rubyforge_project: magrathea
|
70
|
-
rubygems_version: 1.
|
70
|
+
rubygems_version: 1.3.1
|
71
71
|
signing_key:
|
72
72
|
specification_version: 2
|
73
73
|
summary: A powerful Ruby configuration system.
|