configatron 2.1.5 → 2.1.6

Sign up to get free protection for your applications and to get access to all the features.
@@ -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/ProtectedParameter.html" class="link">Configatron::ProtectedParameter</a><br />
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="#M000020">intialize</a>&nbsp;&nbsp;
89
+ <a href="#M000025">intialize</a>&nbsp;&nbsp;
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-M000020" class="method-detail">
112
- <a name="M000020"></a>
111
+ <div id="method-M000025" class="method-detail">
112
+ <a name="M000025"></a>
113
113
 
114
114
  <div class="method-heading">
115
- <a href="#M000020" class="method-signature">
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('M000020-source');return false;">[Source]</a></p>
123
- <div class="method-source-code" id="M000020-source">
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>&nbsp;&nbsp;
90
90
  <a href="#M000010">configure_from_yaml</a>&nbsp;&nbsp;
91
- <a href="#M000019">deep_clone</a>&nbsp;&nbsp;
91
+ <a href="#M000021">deep_clone</a>&nbsp;&nbsp;
92
92
  <a href="#M000008">inspect</a>&nbsp;&nbsp;
93
+ <a href="#M000019">lock</a>&nbsp;&nbsp;
94
+ <a href="#M000022">lock!</a>&nbsp;&nbsp;
93
95
  <a href="#M000006">new</a>&nbsp;&nbsp;
94
96
  <a href="#M000011">nil?</a>&nbsp;&nbsp;
95
97
  <a href="#M000015">protect</a>&nbsp;&nbsp;
@@ -98,6 +100,8 @@
98
100
  <a href="#M000012">retrieve</a>&nbsp;&nbsp;
99
101
  <a href="#M000014">set_default</a>&nbsp;&nbsp;
100
102
  <a href="#M000007">to_hash</a>&nbsp;&nbsp;
103
+ <a href="#M000020">unlock</a>&nbsp;&nbsp;
104
+ <a href="#M000023">unlock!</a>&nbsp;&nbsp;
101
105
  <a href="#M000017">unprotect</a>&nbsp;&nbsp;
102
106
  <a href="#M000018">unprotect_all!</a>&nbsp;&nbsp;
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-M000019" class="method-detail">
217
- <a name="M000019"></a>
220
+ <div id="method-M000021" class="method-detail">
221
+ <a name="M000021"></a>
218
222
 
219
223
  <div class="method-heading">
220
- <a href="#M000019" class="method-signature">
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('M000019-source');return false;">[Source]</a></p>
269
- <div class="method-source-code" id="M000019-source">
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 176</span>
272
- 176: <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>={} )
273
- 177: <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> )
274
- 178: <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>]
275
- 179: <span class="ruby-keyword kw">else</span>
276
- 180: <span class="ruby-keyword kw">begin</span>
277
- 181: <span class="ruby-identifier">cl</span> = <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">clone</span>
278
- 182: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span>
279
- 183: <span class="ruby-comment cmt"># unclonnable (TrueClass, Fixnum, ...)</span>
280
- 184: <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>
281
- 185: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">obj</span>
282
- 186: <span class="ruby-keyword kw">else</span>
283
- 187: <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>
284
- 188: <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>
285
- 189: <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> )
286
- 190: <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>
287
- 191: <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> )
288
- 192: }
289
- 193: <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> )
290
- 194: <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>
291
- 195: <span class="ruby-identifier">deep_clone</span>( <span class="ruby-identifier">v</span>, <span class="ruby-identifier">cloned</span> )
292
- 196: }
293
- 197: <span class="ruby-keyword kw">end</span>
294
- 198: <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>
295
- 199: <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> )
296
- 200: <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> )
297
- 201: <span class="ruby-identifier">cl</span>.<span class="ruby-identifier">instance_eval</span>( <span class="ruby-node">&quot;#{var} = v_cl&quot;</span> )
298
- 202: <span class="ruby-keyword kw">end</span>
299
- 203: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">cl</span>
300
- 204: <span class="ruby-keyword kw">end</span>
301
- 205: <span class="ruby-keyword kw">end</span>
302
- 206: <span class="ruby-keyword kw">end</span>
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">&quot;#{var} = v_cl&quot;</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">&quot;Namespace #{name.inspect} does not exist&quot;</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 113</span>
404
- 113: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">protect</span>(<span class="ruby-identifier">name</span>)
405
- 114: <span class="ruby-ivar">@_protected</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_sym</span>
406
- 115: <span class="ruby-keyword kw">end</span>
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">&lt;&lt;</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 118</span>
430
- 118: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">protect_all!</span>
431
- 119: <span class="ruby-ivar">@_protected</span>.<span class="ruby-identifier">clear</span>
432
- 120: <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>
433
- 121: <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>)
434
- 122: <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>
435
- 123: <span class="ruby-ivar">@_protected</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">k</span>
436
- 124: <span class="ruby-keyword kw">end</span>
437
- 125: <span class="ruby-keyword kw">end</span>
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">&lt;&lt;</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">&quot;Namespace #{name.inspect} does not exist&quot;</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 128</span>
570
- 128: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">unprotect</span>(<span class="ruby-identifier">name</span>)
571
- 129: <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> }
572
- 130: <span class="ruby-keyword kw">end</span>
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 132</span>
593
- 132: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">unprotect_all!</span>
594
- 133: <span class="ruby-ivar">@_protected</span>.<span class="ruby-identifier">clear</span>
595
- 134: <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>
596
- 135: <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>)
597
- 136: <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>
598
- 137: <span class="ruby-keyword kw">end</span>
599
- 138: <span class="ruby-keyword kw">end</span>
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>
@@ -80,7 +80,7 @@
80
80
  <h3 class="section-bar">Methods</h3>
81
81
 
82
82
  <div class="name-list">
83
- <a href="#M000021">configatron</a>&nbsp;&nbsp;
83
+ <a href="#M000026">configatron</a>&nbsp;&nbsp;
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-M000021" class="method-detail">
106
- <a name="M000021"></a>
105
+ <div id="method-M000026" class="method-detail">
106
+ <a name="M000026"></a>
107
107
 
108
108
  <div class="method-heading">
109
- <a href="#M000021" class="method-signature">
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('M000021-source');return false;">[Source]</a></p>
121
- <div class="method-source-code" id="M000021-source">
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
- Wed, 08 Oct 2008 08:34:31 -0400
1
+ Fri, 21 Nov 2008 19:05:37 -0500
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Wed Sep 17 15:16:26 -0400 2008</td>
59
+ <td>Fri Nov 21 19:04:32 -0500 2008</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Wed Oct 08 08:27:34 -0400 2008</td>
59
+ <td>Fri Nov 21 19:04:32 -0500 2008</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -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 />
@@ -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#M000021">configatron (Kernel)</a><br />
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#M000019">deep_clone (Configatron::Store)</a><br />
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#M000020">intialize (Configatron::ProtectedParameter)</a><br />
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>
@@ -4,4 +4,10 @@ class Configatron
4
4
  super("Can not modify protected parameter: '#{name}'")
5
5
  end
6
6
  end
7
- end
7
+
8
+ class LockedNamespace < StandardError
9
+ def initialize(name)
10
+ super("Cannot add new parameters to locked namespace: #{name.inspect}")
11
+ end
12
+ end
13
+ end
@@ -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.5
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-10-08 00:00:00 -04:00
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.2.0
70
+ rubygems_version: 1.3.1
71
71
  signing_key:
72
72
  specification_version: 2
73
73
  summary: A powerful Ruby configuration system.