configatron 2.1.0 → 2.1.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -181,27 +181,30 @@ Allows for the configuration of the system via a Hash
181
181
 
182
182
  <div class="method-heading">
183
183
  <a href="#M000007" class="method-signature">
184
- <span class="method-name">configure_from_yaml</span><span class="method-args">(path)</span>
184
+ <span class="method-name">configure_from_yaml</span><span class="method-args">(path, opts = {})</span>
185
185
  </a>
186
186
  </div>
187
187
 
188
188
  <div class="method-description">
189
189
  <p>
190
190
  Allows for the configuration of the system from a YAML file. Takes the path
191
- to the YAML file.
191
+ to the YAML file. Also takes an optional parameter, <tt>:hash</tt>, that
192
+ indicates a specific hash that should be loaded from the file.
192
193
  </p>
193
194
  <p><a class="source-toggle" href="#"
194
195
  onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
195
196
  <div class="method-source-code" id="M000007-source">
196
197
  <pre>
197
- <span class="ruby-comment cmt"># File lib/configatron/store.rb, line 27</span>
198
- 27: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">configure_from_yaml</span>(<span class="ruby-identifier">path</span>)
199
- 28: <span class="ruby-keyword kw">begin</span>
200
- 29: <span class="ruby-identifier">configure_from_hash</span>(<span class="ruby-constant">YAML</span>.<span class="ruby-identifier">load</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>)))
201
- 30: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">ENOENT</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
202
- 31: <span class="ruby-identifier">puts</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>
203
- 32: <span class="ruby-keyword kw">end</span>
204
- 33: <span class="ruby-keyword kw">end</span>
198
+ <span class="ruby-comment cmt"># File lib/configatron/store.rb, line 29</span>
199
+ 29: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">configure_from_yaml</span>(<span class="ruby-identifier">path</span>, <span class="ruby-identifier">opts</span> = {})
200
+ 30: <span class="ruby-keyword kw">begin</span>
201
+ 31: <span class="ruby-identifier">yml</span> = <span class="ruby-constant">YAML</span>.<span class="ruby-identifier">load</span>(<span class="ruby-constant">File</span>.<span class="ruby-identifier">read</span>(<span class="ruby-identifier">path</span>))
202
+ 32: <span class="ruby-identifier">yml</span> = <span class="ruby-identifier">yml</span>[<span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:hash</span>]] <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">opts</span>[<span class="ruby-identifier">:hash</span>].<span class="ruby-identifier">nil?</span>
203
+ 33: <span class="ruby-identifier">configure_from_hash</span>(<span class="ruby-identifier">yml</span>)
204
+ 34: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Errno</span><span class="ruby-operator">::</span><span class="ruby-constant">ENOENT</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
205
+ 35: <span class="ruby-identifier">puts</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>
206
+ 36: <span class="ruby-keyword kw">end</span>
207
+ 37: <span class="ruby-keyword kw">end</span>
205
208
  </pre>
206
209
  </div>
207
210
  </div>
@@ -262,38 +265,38 @@ href="http://simplypowerful.1984.cz/goodlibs/1.2006.05.23">simplypowerful.1984.c
262
265
  onclick="toggleCode('M000016-source');return false;">[Source]</a></p>
263
266
  <div class="method-source-code" id="M000016-source">
264
267
  <pre>
265
- <span class="ruby-comment cmt"># File lib/configatron/store.rb, line 143</span>
266
- 143: <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>={} )
267
- 144: <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> )
268
- 145: <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>]
269
- 146: <span class="ruby-keyword kw">else</span>
270
- 147: <span class="ruby-keyword kw">begin</span>
271
- 148: <span class="ruby-identifier">cl</span> = <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">clone</span>
272
- 149: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span>
273
- 150: <span class="ruby-comment cmt"># unclonnable (TrueClass, Fixnum, ...)</span>
274
- 151: <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>
275
- 152: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">obj</span>
276
- 153: <span class="ruby-keyword kw">else</span>
277
- 154: <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>
278
- 155: <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>
279
- 156: <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> )
280
- 157: <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>
281
- 158: <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> )
282
- 159: }
283
- 160: <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> )
284
- 161: <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>
285
- 162: <span class="ruby-identifier">deep_clone</span>( <span class="ruby-identifier">v</span>, <span class="ruby-identifier">cloned</span> )
268
+ <span class="ruby-comment cmt"># File lib/configatron/store.rb, line 147</span>
269
+ 147: <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>={} )
270
+ 148: <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> )
271
+ 149: <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>]
272
+ 150: <span class="ruby-keyword kw">else</span>
273
+ 151: <span class="ruby-keyword kw">begin</span>
274
+ 152: <span class="ruby-identifier">cl</span> = <span class="ruby-identifier">obj</span>.<span class="ruby-identifier">clone</span>
275
+ 153: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span>
276
+ 154: <span class="ruby-comment cmt"># unclonnable (TrueClass, Fixnum, ...)</span>
277
+ 155: <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>
278
+ 156: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">obj</span>
279
+ 157: <span class="ruby-keyword kw">else</span>
280
+ 158: <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>
281
+ 159: <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>
282
+ 160: <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> )
283
+ 161: <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>
284
+ 162: <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> )
286
285
  163: }
287
- 164: <span class="ruby-keyword kw">end</span>
288
- 165: <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>
289
- 166: <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> )
290
- 167: <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> )
291
- 168: <span class="ruby-identifier">cl</span>.<span class="ruby-identifier">instance_eval</span>( <span class="ruby-node">&quot;#{var} = v_cl&quot;</span> )
292
- 169: <span class="ruby-keyword kw">end</span>
293
- 170: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">cl</span>
294
- 171: <span class="ruby-keyword kw">end</span>
295
- 172: <span class="ruby-keyword kw">end</span>
296
- 173: <span class="ruby-keyword kw">end</span>
286
+ 164: <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> )
287
+ 165: <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>
288
+ 166: <span class="ruby-identifier">deep_clone</span>( <span class="ruby-identifier">v</span>, <span class="ruby-identifier">cloned</span> )
289
+ 167: }
290
+ 168: <span class="ruby-keyword kw">end</span>
291
+ 169: <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>
292
+ 170: <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> )
293
+ 171: <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> )
294
+ 172: <span class="ruby-identifier">cl</span>.<span class="ruby-identifier">instance_eval</span>( <span class="ruby-node">&quot;#{var} = v_cl&quot;</span> )
295
+ 173: <span class="ruby-keyword kw">end</span>
296
+ 174: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">cl</span>
297
+ 175: <span class="ruby-keyword kw">end</span>
298
+ 176: <span class="ruby-keyword kw">end</span>
299
+ 177: <span class="ruby-keyword kw">end</span>
297
300
  </pre>
298
301
  </div>
299
302
  </div>
@@ -316,10 +319,10 @@ Returns true if there are no configuration parameters
316
319
  onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
317
320
  <div class="method-source-code" id="M000008-source">
318
321
  <pre>
319
- <span class="ruby-comment cmt"># File lib/configatron/store.rb, line 36</span>
320
- 36: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">nil?</span>
321
- 37: <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@_store</span>.<span class="ruby-identifier">empty?</span>
322
- 38: <span class="ruby-keyword kw">end</span>
322
+ <span class="ruby-comment cmt"># File lib/configatron/store.rb, line 40</span>
323
+ 40: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">nil?</span>
324
+ 41: <span class="ruby-keyword kw">return</span> <span class="ruby-ivar">@_store</span>.<span class="ruby-identifier">empty?</span>
325
+ 42: <span class="ruby-keyword kw">end</span>
323
326
  </pre>
324
327
  </div>
325
328
  </div>
@@ -344,10 +347,10 @@ well.
344
347
  onclick="toggleCode('M000012-source');return false;">[Source]</a></p>
345
348
  <div class="method-source-code" id="M000012-source">
346
349
  <pre>
347
- <span class="ruby-comment cmt"># File lib/configatron/store.rb, line 80</span>
348
- 80: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">protect</span>(<span class="ruby-identifier">name</span>)
349
- 81: <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>
350
- 82: <span class="ruby-keyword kw">end</span>
350
+ <span class="ruby-comment cmt"># File lib/configatron/store.rb, line 84</span>
351
+ 84: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">protect</span>(<span class="ruby-identifier">name</span>)
352
+ 85: <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>
353
+ 86: <span class="ruby-keyword kw">end</span>
351
354
  </pre>
352
355
  </div>
353
356
  </div>
@@ -370,15 +373,15 @@ Prevents all parameters from being reassigned.
370
373
  onclick="toggleCode('M000013-source');return false;">[Source]</a></p>
371
374
  <div class="method-source-code" id="M000013-source">
372
375
  <pre>
373
- <span class="ruby-comment cmt"># File lib/configatron/store.rb, line 85</span>
374
- 85: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">protect_all!</span>
375
- 86: <span class="ruby-ivar">@_protected</span>.<span class="ruby-identifier">clear</span>
376
- 87: <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>
377
- 88: <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>)
378
- 89: <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>
379
- 90: <span class="ruby-ivar">@_protected</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">k</span>
380
- 91: <span class="ruby-keyword kw">end</span>
381
- 92: <span class="ruby-keyword kw">end</span>
376
+ <span class="ruby-comment cmt"># File lib/configatron/store.rb, line 89</span>
377
+ 89: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">protect_all!</span>
378
+ 90: <span class="ruby-ivar">@_protected</span>.<span class="ruby-identifier">clear</span>
379
+ 91: <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>
380
+ 92: <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>)
381
+ 93: <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>
382
+ 94: <span class="ruby-ivar">@_protected</span> <span class="ruby-operator">&lt;&lt;</span> <span class="ruby-identifier">k</span>
383
+ 95: <span class="ruby-keyword kw">end</span>
384
+ 96: <span class="ruby-keyword kw">end</span>
382
385
  </pre>
383
386
  </div>
384
387
  </div>
@@ -402,10 +405,10 @@ href="Store.html#M000010">remove</a> all below it.
402
405
  onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
403
406
  <div class="method-source-code" id="M000010-source">
404
407
  <pre>
405
- <span class="ruby-comment cmt"># File lib/configatron/store.rb, line 48</span>
406
- 48: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">remove</span>(<span class="ruby-identifier">name</span>)
407
- 49: <span class="ruby-ivar">@_store</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_sym</span>)
408
- 50: <span class="ruby-keyword kw">end</span>
408
+ <span class="ruby-comment cmt"># File lib/configatron/store.rb, line 52</span>
409
+ 52: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">remove</span>(<span class="ruby-identifier">name</span>)
410
+ 53: <span class="ruby-ivar">@_store</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_sym</span>)
411
+ 54: <span class="ruby-keyword kw">end</span>
409
412
  </pre>
410
413
  </div>
411
414
  </div>
@@ -429,10 +432,10 @@ will return the default_value specified.
429
432
  onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
430
433
  <div class="method-source-code" id="M000009-source">
431
434
  <pre>
432
- <span class="ruby-comment cmt"># File lib/configatron/store.rb, line 42</span>
433
- 42: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">retrieve</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">default_value</span> = <span class="ruby-keyword kw">nil</span>)
434
- 43: <span class="ruby-ivar">@_store</span>[<span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_sym</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">default_value</span>
435
- 44: <span class="ruby-keyword kw">end</span>
435
+ <span class="ruby-comment cmt"># File lib/configatron/store.rb, line 46</span>
436
+ 46: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">retrieve</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">default_value</span> = <span class="ruby-keyword kw">nil</span>)
437
+ 47: <span class="ruby-ivar">@_store</span>[<span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_sym</span>] <span class="ruby-operator">||</span> <span class="ruby-identifier">default_value</span>
438
+ 48: <span class="ruby-keyword kw">end</span>
436
439
  </pre>
437
440
  </div>
438
441
  </div>
@@ -456,12 +459,12 @@ it won&#8216;t set the value.
456
459
  onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
457
460
  <div class="method-source-code" id="M000011-source">
458
461
  <pre>
459
- <span class="ruby-comment cmt"># File lib/configatron/store.rb, line 54</span>
460
- 54: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">set_default</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">default_value</span>)
461
- 55: <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@_store</span>[<span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_sym</span>]
462
- 56: <span class="ruby-ivar">@_store</span>[<span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_sym</span>] = <span class="ruby-identifier">parse_options</span>(<span class="ruby-identifier">default_value</span>)
463
- 57: <span class="ruby-keyword kw">end</span>
464
- 58: <span class="ruby-keyword kw">end</span>
462
+ <span class="ruby-comment cmt"># File lib/configatron/store.rb, line 58</span>
463
+ 58: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">set_default</span>(<span class="ruby-identifier">name</span>, <span class="ruby-identifier">default_value</span>)
464
+ 59: <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@_store</span>[<span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_sym</span>]
465
+ 60: <span class="ruby-ivar">@_store</span>[<span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_sym</span>] = <span class="ruby-identifier">parse_options</span>(<span class="ruby-identifier">default_value</span>)
466
+ 61: <span class="ruby-keyword kw">end</span>
467
+ 62: <span class="ruby-keyword kw">end</span>
465
468
  </pre>
466
469
  </div>
467
470
  </div>
@@ -510,10 +513,10 @@ Removes the protection of a parameter.
510
513
  onclick="toggleCode('M000014-source');return false;">[Source]</a></p>
511
514
  <div class="method-source-code" id="M000014-source">
512
515
  <pre>
513
- <span class="ruby-comment cmt"># File lib/configatron/store.rb, line 95</span>
514
- 95: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">unprotect</span>(<span class="ruby-identifier">name</span>)
515
- 96: <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> }
516
- 97: <span class="ruby-keyword kw">end</span>
516
+ <span class="ruby-comment cmt"># File lib/configatron/store.rb, line 99</span>
517
+ 99: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">unprotect</span>(<span class="ruby-identifier">name</span>)
518
+ 100: <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> }
519
+ 101: <span class="ruby-keyword kw">end</span>
517
520
  </pre>
518
521
  </div>
519
522
  </div>
@@ -533,14 +536,14 @@ Removes the protection of a parameter.
533
536
  onclick="toggleCode('M000015-source');return false;">[Source]</a></p>
534
537
  <div class="method-source-code" id="M000015-source">
535
538
  <pre>
536
- <span class="ruby-comment cmt"># File lib/configatron/store.rb, line 99</span>
537
- 99: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">unprotect_all!</span>
538
- 100: <span class="ruby-ivar">@_protected</span>.<span class="ruby-identifier">clear</span>
539
- 101: <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>
540
- 102: <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>)
541
- 103: <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>
542
- 104: <span class="ruby-keyword kw">end</span>
543
- 105: <span class="ruby-keyword kw">end</span>
539
+ <span class="ruby-comment cmt"># File lib/configatron/store.rb, line 103</span>
540
+ 103: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">unprotect_all!</span>
541
+ 104: <span class="ruby-ivar">@_protected</span>.<span class="ruby-identifier">clear</span>
542
+ 105: <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>
543
+ 106: <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>)
544
+ 107: <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>
545
+ 108: <span class="ruby-keyword kw">end</span>
546
+ 109: <span class="ruby-keyword kw">end</span>
544
547
  </pre>
545
548
  </div>
546
549
  </div>
@@ -1 +1 @@
1
- Thu, 18 Sep 2008 12:40:45 -0400
1
+ Thu, 18 Sep 2008 13:09:10 -0400
@@ -56,7 +56,7 @@
56
56
  </tr>
57
57
  <tr class="top-aligned-row">
58
58
  <td><strong>Last Update:</strong></td>
59
- <td>Thu Sep 18 12:39:14 -0400 2008</td>
59
+ <td>Thu Sep 18 13:08:55 -0400 2008</td>
60
60
  </tr>
61
61
  </table>
62
62
  </div>
@@ -23,10 +23,14 @@ class Configatron
23
23
  end
24
24
 
25
25
  # Allows for the configuration of the system from a YAML file.
26
- # Takes the path to the YAML file.
27
- def configure_from_yaml(path)
26
+ # Takes the path to the YAML file. Also takes an optional parameter,
27
+ # <tt>:hash</tt>, that indicates a specific hash that should be
28
+ # loaded from the file.
29
+ def configure_from_yaml(path, opts = {})
28
30
  begin
29
- configure_from_hash(YAML.load(File.read(path)))
31
+ yml = YAML.load(File.read(path))
32
+ yml = yml[opts[:hash]] unless opts[:hash].nil?
33
+ configure_from_hash(yml)
30
34
  rescue Errno::ENOENT => e
31
35
  puts e.message
32
36
  end
@@ -154,6 +154,15 @@ describe "configatron" do
154
154
  lambda{configatron.configure_from_yaml('i_dont_exist.yml')}.should_not raise_error
155
155
  end
156
156
 
157
+ it "should be able to load a specific hash from the file" do
158
+ configatron.others.should be_nil
159
+ configatron.survivors.should be_nil
160
+ configatron.configure_from_yaml(File.join(File.dirname(__FILE__), 'lost.yml'), :hash => "survivors")
161
+ configatron.others.should be_nil
162
+ configatron.survivors.should be_nil
163
+ configatron.on_island.jack.should == 'Jack Shepherd'
164
+ end
165
+
157
166
  end
158
167
 
159
168
  it 'should return a parameter' do
@@ -0,0 +1,14 @@
1
+ others:
2
+ on_island:
3
+ ben: Benjamin Linus
4
+ richard: Richard Alpert
5
+ deceased:
6
+ goodwin: Goodwin Stanhope
7
+ mikhail: Mikhail Bakunin
8
+ survivors:
9
+ on_island:
10
+ jack: Jack Shepherd
11
+ locke: John Locke
12
+ deceased:
13
+ charlie: Charlie Pace
14
+ michael: Michael Dawson
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.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - markbates
@@ -75,5 +75,6 @@ test_files:
75
75
  - spec/lib
76
76
  - spec/lib/configatron_spec.rb
77
77
  - spec/lib/futurama.yml
78
+ - spec/lib/lost.yml
78
79
  - spec/spec.opts
79
80
  - spec/spec_helper.rb