configatron 1.0.1 → 1.1.0
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/Configuration.html +104 -69
- data/doc/classes/Configatron/Store.html +28 -0
- data/doc/classes/Configatron/YamlStore.html +203 -0
- data/doc/classes/Kernel.html +6 -6
- data/doc/created.rid +1 -1
- data/doc/files/lib/configatron_rb.html +2 -1
- data/doc/files/lib/configuration_rb.html +1 -1
- data/doc/files/lib/store_rb.html +1 -1
- data/doc/files/lib/yaml_store_rb.html +101 -0
- data/doc/fr_class_index.html +1 -0
- data/doc/fr_file_index.html +1 -0
- data/doc/fr_method_index.html +11 -7
- data/lib/configatron.rb +2 -0
- data/lib/configuration.rb +13 -0
- data/lib/store.rb +5 -0
- data/lib/yaml_store.rb +33 -0
- data/spec/unit/configuration_spec.rb +61 -0
- data/spec/unit/family_guy.yml +2 -0
- metadata +6 -2
@@ -92,12 +92,13 @@ The central class for managing the configurations.
|
|
92
92
|
<h3 class="section-bar">Methods</h3>
|
93
93
|
|
94
94
|
<div class="name-list">
|
95
|
-
<a href="#
|
96
|
-
<a href="#
|
97
|
-
<a href="#
|
98
|
-
<a href="#
|
99
|
-
<a href="#
|
100
|
-
<a href="#
|
95
|
+
<a href="#M000010">configure</a>
|
96
|
+
<a href="#M000011">configure_from_hash</a>
|
97
|
+
<a href="#M000012">configure_from_yaml</a>
|
98
|
+
<a href="#M000013">reload</a>
|
99
|
+
<a href="#M000015">reset</a>
|
100
|
+
<a href="#M000014">reset!</a>
|
101
|
+
<a href="#M000016">revert</a>
|
101
102
|
</div>
|
102
103
|
</div>
|
103
104
|
|
@@ -145,11 +146,11 @@ NoMethodError exception will be raised.
|
|
145
146
|
<div id="methods">
|
146
147
|
<h3 class="section-bar">Public Instance methods</h3>
|
147
148
|
|
148
|
-
<div id="method-
|
149
|
-
<a name="
|
149
|
+
<div id="method-M000010" class="method-detail">
|
150
|
+
<a name="M000010"></a>
|
150
151
|
|
151
152
|
<div class="method-heading">
|
152
|
-
<a href="#
|
153
|
+
<a href="#M000010" class="method-signature">
|
153
154
|
<span class="method-name">configure</span><span class="method-args">() {|storage| ...}</span>
|
154
155
|
</a>
|
155
156
|
</div>
|
@@ -159,8 +160,8 @@ NoMethodError exception will be raised.
|
|
159
160
|
Yields a new <a href="Store.html">Configatron::Store</a> class.
|
160
161
|
</p>
|
161
162
|
<p><a class="source-toggle" href="#"
|
162
|
-
onclick="toggleCode('
|
163
|
-
<div class="method-source-code" id="
|
163
|
+
onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
|
164
|
+
<div class="method-source-code" id="M000010-source">
|
164
165
|
<pre>
|
165
166
|
<span class="ruby-comment cmt"># File lib/configuration.rb, line 18</span>
|
166
167
|
18: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">configure</span>
|
@@ -176,11 +177,11 @@ Yields a new <a href="Store.html">Configatron::Store</a> class.
|
|
176
177
|
</div>
|
177
178
|
</div>
|
178
179
|
|
179
|
-
<div id="method-
|
180
|
-
<a name="
|
180
|
+
<div id="method-M000011" class="method-detail">
|
181
|
+
<a name="M000011"></a>
|
181
182
|
|
182
183
|
<div class="method-heading">
|
183
|
-
<a href="#
|
184
|
+
<a href="#M000011" class="method-signature">
|
184
185
|
<span class="method-name">configure_from_hash</span><span class="method-args">(parameters)</span>
|
185
186
|
</a>
|
186
187
|
</div>
|
@@ -190,8 +191,8 @@ Yields a new <a href="Store.html">Configatron::Store</a> class.
|
|
190
191
|
Used to load configuration settings from a Hash.
|
191
192
|
</p>
|
192
193
|
<p><a class="source-toggle" href="#"
|
193
|
-
onclick="toggleCode('
|
194
|
-
<div class="method-source-code" id="
|
194
|
+
onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
|
195
|
+
<div class="method-source-code" id="M000011-source">
|
195
196
|
<pre>
|
196
197
|
<span class="ruby-comment cmt"># File lib/configuration.rb, line 28</span>
|
197
198
|
28: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">configure_from_hash</span>(<span class="ruby-identifier">parameters</span>)
|
@@ -204,11 +205,44 @@ Used to load configuration settings from a Hash.
|
|
204
205
|
</div>
|
205
206
|
</div>
|
206
207
|
|
207
|
-
<div id="method-
|
208
|
-
<a name="
|
208
|
+
<div id="method-M000012" class="method-detail">
|
209
|
+
<a name="M000012"></a>
|
209
210
|
|
210
211
|
<div class="method-heading">
|
211
|
-
<a href="#
|
212
|
+
<a href="#M000012" class="method-signature">
|
213
|
+
<span class="method-name">configure_from_yaml</span><span class="method-args">(path)</span>
|
214
|
+
</a>
|
215
|
+
</div>
|
216
|
+
|
217
|
+
<div class="method-description">
|
218
|
+
<p>
|
219
|
+
Used to load configuration settings from a YAML file.
|
220
|
+
</p>
|
221
|
+
<p><a class="source-toggle" href="#"
|
222
|
+
onclick="toggleCode('M000012-source');return false;">[Source]</a></p>
|
223
|
+
<div class="method-source-code" id="M000012-source">
|
224
|
+
<pre>
|
225
|
+
<span class="ruby-comment cmt"># File lib/configuration.rb, line 35</span>
|
226
|
+
35: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">configure_from_yaml</span>(<span class="ruby-identifier">path</span>)
|
227
|
+
36: <span class="ruby-keyword kw">begin</span>
|
228
|
+
37: <span class="ruby-identifier">storage</span> = <span class="ruby-constant">Configatron</span><span class="ruby-operator">::</span><span class="ruby-constant">YamlStore</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">path</span>)
|
229
|
+
38: <span class="ruby-ivar">@_storage_list</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">storage</span>
|
230
|
+
39: <span class="ruby-identifier">load_methods</span>(<span class="ruby-identifier">storage</span>)
|
231
|
+
40: <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">></span> <span class="ruby-identifier">e</span>
|
232
|
+
41: <span class="ruby-identifier">puts</span> <span class="ruby-identifier">e</span>.<span class="ruby-identifier">message</span>
|
233
|
+
42: <span class="ruby-comment cmt"># file doesn't exist.</span>
|
234
|
+
43: <span class="ruby-keyword kw">end</span>
|
235
|
+
44: <span class="ruby-keyword kw">end</span>
|
236
|
+
</pre>
|
237
|
+
</div>
|
238
|
+
</div>
|
239
|
+
</div>
|
240
|
+
|
241
|
+
<div id="method-M000013" class="method-detail">
|
242
|
+
<a name="M000013"></a>
|
243
|
+
|
244
|
+
<div class="method-heading">
|
245
|
+
<a href="#M000013" class="method-signature">
|
212
246
|
<span class="method-name">reload</span><span class="method-args">()</span>
|
213
247
|
</a>
|
214
248
|
</div>
|
@@ -218,25 +252,26 @@ Used to load configuration settings from a Hash.
|
|
218
252
|
Replays the history of configurations.
|
219
253
|
</p>
|
220
254
|
<p><a class="source-toggle" href="#"
|
221
|
-
onclick="toggleCode('
|
222
|
-
<div class="method-source-code" id="
|
255
|
+
onclick="toggleCode('M000013-source');return false;">[Source]</a></p>
|
256
|
+
<div class="method-source-code" id="M000013-source">
|
223
257
|
<pre>
|
224
|
-
<span class="ruby-comment cmt"># File lib/configuration.rb, line
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
258
|
+
<span class="ruby-comment cmt"># File lib/configuration.rb, line 47</span>
|
259
|
+
47: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">reload</span>
|
260
|
+
48: <span class="ruby-ivar">@_storage_list</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">storage</span><span class="ruby-operator">|</span>
|
261
|
+
49: <span class="ruby-identifier">storage</span>.<span class="ruby-identifier">reload</span>
|
262
|
+
50: <span class="ruby-identifier">load_methods</span>(<span class="ruby-identifier">storage</span>)
|
263
|
+
51: <span class="ruby-keyword kw">end</span>
|
264
|
+
52: <span class="ruby-keyword kw">end</span>
|
230
265
|
</pre>
|
231
266
|
</div>
|
232
267
|
</div>
|
233
268
|
</div>
|
234
269
|
|
235
|
-
<div id="method-
|
236
|
-
<a name="
|
270
|
+
<div id="method-M000015" class="method-detail">
|
271
|
+
<a name="M000015"></a>
|
237
272
|
|
238
273
|
<div class="method-heading">
|
239
|
-
<a href="#
|
274
|
+
<a href="#M000015" class="method-signature">
|
240
275
|
<span class="method-name">reset</span><span class="method-args">()</span>
|
241
276
|
</a>
|
242
277
|
</div>
|
@@ -246,64 +281,64 @@ Replays the history of configurations.
|
|
246
281
|
All methods are undefined.
|
247
282
|
</p>
|
248
283
|
<p><a class="source-toggle" href="#"
|
249
|
-
onclick="toggleCode('
|
250
|
-
<div class="method-source-code" id="
|
284
|
+
onclick="toggleCode('M000015-source');return false;">[Source]</a></p>
|
285
|
+
<div class="method-source-code" id="M000015-source">
|
251
286
|
<pre>
|
252
|
-
<span class="ruby-comment cmt"># File lib/configuration.rb, line
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
287
|
+
<span class="ruby-comment cmt"># File lib/configuration.rb, line 64</span>
|
288
|
+
64: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">reset</span>
|
289
|
+
65: <span class="ruby-ivar">@_storage_list</span>.<span class="ruby-identifier">each</span> <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">storage</span><span class="ruby-operator">|</span>
|
290
|
+
66: <span class="ruby-identifier">storage</span>.<span class="ruby-identifier">parameters</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-identifier">v</span><span class="ruby-operator">|</span>
|
291
|
+
67: <span class="ruby-constant">Configatron</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">instance_eval</span> <span class="ruby-keyword kw">do</span>
|
292
|
+
68: <span class="ruby-keyword kw">begin</span>
|
293
|
+
69: <span class="ruby-identifier">undef_method</span>(<span class="ruby-identifier">k</span>)
|
294
|
+
70: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">NameError</span> =<span class="ruby-operator">></span> <span class="ruby-identifier">e</span>
|
295
|
+
71: <span class="ruby-keyword kw">end</span>
|
296
|
+
72: <span class="ruby-keyword kw">end</span>
|
297
|
+
73: <span class="ruby-keyword kw">end</span>
|
298
|
+
74: <span class="ruby-keyword kw">end</span>
|
299
|
+
75: <span class="ruby-keyword kw">end</span>
|
265
300
|
</pre>
|
266
301
|
</div>
|
267
302
|
</div>
|
268
303
|
</div>
|
269
304
|
|
270
|
-
<div id="method-
|
271
|
-
<a name="
|
305
|
+
<div id="method-M000014" class="method-detail">
|
306
|
+
<a name="M000014"></a>
|
272
307
|
|
273
308
|
<div class="method-heading">
|
274
|
-
<a href="#
|
309
|
+
<a href="#M000014" class="method-signature">
|
275
310
|
<span class="method-name">reset!</span><span class="method-args">()</span>
|
276
311
|
</a>
|
277
312
|
</div>
|
278
313
|
|
279
314
|
<div class="method-description">
|
280
315
|
<p>
|
281
|
-
Does a hard <a href="Configuration.html#
|
316
|
+
Does a hard <a href="Configuration.html#M000015">reset</a> of the <a
|
282
317
|
href="Configuration.html">Configatron::Configuration</a> class. All methods
|
283
318
|
are undefined, the list of configuration parameters is emptied, and the
|
284
|
-
nil_for_missing method gets <a href="Configuration.html#
|
319
|
+
nil_for_missing method gets <a href="Configuration.html#M000015">reset</a>
|
285
320
|
to false.
|
286
321
|
</p>
|
287
322
|
<p><a class="source-toggle" href="#"
|
288
|
-
onclick="toggleCode('
|
289
|
-
<div class="method-source-code" id="
|
323
|
+
onclick="toggleCode('M000014-source');return false;">[Source]</a></p>
|
324
|
+
<div class="method-source-code" id="M000014-source">
|
290
325
|
<pre>
|
291
|
-
<span class="ruby-comment cmt"># File lib/configuration.rb, line
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
326
|
+
<span class="ruby-comment cmt"># File lib/configuration.rb, line 57</span>
|
327
|
+
57: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">reset!</span>
|
328
|
+
58: <span class="ruby-identifier">reset</span>
|
329
|
+
59: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">nil_for_missing</span> = <span class="ruby-keyword kw">false</span>
|
330
|
+
60: <span class="ruby-ivar">@_storage_list</span> = []
|
331
|
+
61: <span class="ruby-keyword kw">end</span>
|
297
332
|
</pre>
|
298
333
|
</div>
|
299
334
|
</div>
|
300
335
|
</div>
|
301
336
|
|
302
|
-
<div id="method-
|
303
|
-
<a name="
|
337
|
+
<div id="method-M000016" class="method-detail">
|
338
|
+
<a name="M000016"></a>
|
304
339
|
|
305
340
|
<div class="method-heading">
|
306
|
-
<a href="#
|
341
|
+
<a href="#M000016" class="method-signature">
|
307
342
|
<span class="method-name">revert</span><span class="method-args">(step = 1)</span>
|
308
343
|
</a>
|
309
344
|
</div>
|
@@ -313,15 +348,15 @@ to false.
|
|
313
348
|
Peels back n number of configuration parameters.
|
314
349
|
</p>
|
315
350
|
<p><a class="source-toggle" href="#"
|
316
|
-
onclick="toggleCode('
|
317
|
-
<div class="method-source-code" id="
|
351
|
+
onclick="toggleCode('M000016-source');return false;">[Source]</a></p>
|
352
|
+
<div class="method-source-code" id="M000016-source">
|
318
353
|
<pre>
|
319
|
-
<span class="ruby-comment cmt"># File lib/configuration.rb, line
|
320
|
-
|
321
|
-
|
322
|
-
|
323
|
-
|
324
|
-
|
354
|
+
<span class="ruby-comment cmt"># File lib/configuration.rb, line 78</span>
|
355
|
+
78: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">revert</span>(<span class="ruby-identifier">step</span> = <span class="ruby-value">1</span>)
|
356
|
+
79: <span class="ruby-identifier">reset</span>
|
357
|
+
80: <span class="ruby-identifier">step</span>.<span class="ruby-identifier">times</span> {<span class="ruby-ivar">@_storage_list</span>.<span class="ruby-identifier">pop</span>}
|
358
|
+
81: <span class="ruby-identifier">reload</span>
|
359
|
+
82: <span class="ruby-keyword kw">end</span>
|
325
360
|
</pre>
|
326
361
|
</div>
|
327
362
|
</div>
|
@@ -96,6 +96,7 @@ Used to store each of the ‘sets’ of configuration parameters.
|
|
96
96
|
<a href="#M000004">method_missing</a>
|
97
97
|
<a href="#M000006">namespace</a>
|
98
98
|
<a href="#M000003">new</a>
|
99
|
+
<a href="#M000007">reload</a>
|
99
100
|
</div>
|
100
101
|
</div>
|
101
102
|
|
@@ -266,6 +267,33 @@ parameters.
|
|
266
267
|
</div>
|
267
268
|
</div>
|
268
269
|
|
270
|
+
<div id="method-M000007" class="method-detail">
|
271
|
+
<a name="M000007"></a>
|
272
|
+
|
273
|
+
<div class="method-heading">
|
274
|
+
<a href="#M000007" class="method-signature">
|
275
|
+
<span class="method-name">reload</span><span class="method-args">()</span>
|
276
|
+
</a>
|
277
|
+
</div>
|
278
|
+
|
279
|
+
<div class="method-description">
|
280
|
+
<p>
|
281
|
+
Called when a <a href="Store.html#M000007">reload</a> is called on
|
282
|
+
configatron. Useful for subclasses that may need to read a file in,
|
283
|
+
etc…
|
284
|
+
</p>
|
285
|
+
<p><a class="source-toggle" href="#"
|
286
|
+
onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
|
287
|
+
<div class="method-source-code" id="M000007-source">
|
288
|
+
<pre>
|
289
|
+
<span class="ruby-comment cmt"># File lib/store.rb, line 50</span>
|
290
|
+
50: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">reload</span>
|
291
|
+
51: <span class="ruby-keyword kw">end</span>
|
292
|
+
</pre>
|
293
|
+
</div>
|
294
|
+
</div>
|
295
|
+
</div>
|
296
|
+
|
269
297
|
|
270
298
|
</div>
|
271
299
|
|
@@ -0,0 +1,203 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
+
<head>
|
8
|
+
<title>Class: Configatron::YamlStore</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
12
|
+
<script type="text/javascript">
|
13
|
+
// <![CDATA[
|
14
|
+
|
15
|
+
function popupCode( url ) {
|
16
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
+
}
|
18
|
+
|
19
|
+
function toggleCode( id ) {
|
20
|
+
if ( document.getElementById )
|
21
|
+
elem = document.getElementById( id );
|
22
|
+
else if ( document.all )
|
23
|
+
elem = eval( "document.all." + id );
|
24
|
+
else
|
25
|
+
return false;
|
26
|
+
|
27
|
+
elemStyle = elem.style;
|
28
|
+
|
29
|
+
if ( elemStyle.display != "block" ) {
|
30
|
+
elemStyle.display = "block"
|
31
|
+
} else {
|
32
|
+
elemStyle.display = "none"
|
33
|
+
}
|
34
|
+
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Make codeblocks hidden by default
|
39
|
+
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
+
|
41
|
+
// ]]>
|
42
|
+
</script>
|
43
|
+
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<div id="classHeader">
|
50
|
+
<table class="header-table">
|
51
|
+
<tr class="top-aligned-row">
|
52
|
+
<td><strong>Class</strong></td>
|
53
|
+
<td class="class-name-in-header">Configatron::YamlStore</td>
|
54
|
+
</tr>
|
55
|
+
<tr class="top-aligned-row">
|
56
|
+
<td><strong>In:</strong></td>
|
57
|
+
<td>
|
58
|
+
<a href="../../files/lib/yaml_store_rb.html">
|
59
|
+
lib/yaml_store.rb
|
60
|
+
</a>
|
61
|
+
<br />
|
62
|
+
</td>
|
63
|
+
</tr>
|
64
|
+
|
65
|
+
<tr class="top-aligned-row">
|
66
|
+
<td><strong>Parent:</strong></td>
|
67
|
+
<td>
|
68
|
+
<a href="Store.html">
|
69
|
+
Configatron::Store
|
70
|
+
</a>
|
71
|
+
</td>
|
72
|
+
</tr>
|
73
|
+
</table>
|
74
|
+
</div>
|
75
|
+
<!-- banner header -->
|
76
|
+
|
77
|
+
<div id="bodyContent">
|
78
|
+
|
79
|
+
|
80
|
+
|
81
|
+
<div id="contextContent">
|
82
|
+
|
83
|
+
<div id="description">
|
84
|
+
<p>
|
85
|
+
Used to store each of the ‘sets’ of configuration parameters
|
86
|
+
that came from a YAML file.
|
87
|
+
</p>
|
88
|
+
|
89
|
+
</div>
|
90
|
+
|
91
|
+
|
92
|
+
</div>
|
93
|
+
|
94
|
+
<div id="method-list">
|
95
|
+
<h3 class="section-bar">Methods</h3>
|
96
|
+
|
97
|
+
<div class="name-list">
|
98
|
+
<a href="#M000008">new</a>
|
99
|
+
<a href="#M000009">reload</a>
|
100
|
+
</div>
|
101
|
+
</div>
|
102
|
+
|
103
|
+
</div>
|
104
|
+
|
105
|
+
|
106
|
+
<!-- if includes -->
|
107
|
+
|
108
|
+
<div id="section">
|
109
|
+
|
110
|
+
|
111
|
+
|
112
|
+
|
113
|
+
|
114
|
+
<div id="attribute-list">
|
115
|
+
<h3 class="section-bar">Attributes</h3>
|
116
|
+
|
117
|
+
<div class="name-list">
|
118
|
+
<table>
|
119
|
+
<tr class="top-aligned-row context-row">
|
120
|
+
<td class="context-item-name">file_location</td>
|
121
|
+
<td class="context-item-value"> [RW] </td>
|
122
|
+
<td class="context-item-desc"></td>
|
123
|
+
</tr>
|
124
|
+
</table>
|
125
|
+
</div>
|
126
|
+
</div>
|
127
|
+
|
128
|
+
|
129
|
+
|
130
|
+
<!-- if method_list -->
|
131
|
+
<div id="methods">
|
132
|
+
<h3 class="section-bar">Public Class methods</h3>
|
133
|
+
|
134
|
+
<div id="method-M000008" class="method-detail">
|
135
|
+
<a name="M000008"></a>
|
136
|
+
|
137
|
+
<div class="method-heading">
|
138
|
+
<a href="#M000008" class="method-signature">
|
139
|
+
<span class="method-name">new</span><span class="method-args">(file_location)</span>
|
140
|
+
</a>
|
141
|
+
</div>
|
142
|
+
|
143
|
+
<div class="method-description">
|
144
|
+
<p>
|
145
|
+
Takes the full path to the YAML file.
|
146
|
+
</p>
|
147
|
+
<p><a class="source-toggle" href="#"
|
148
|
+
onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
|
149
|
+
<div class="method-source-code" id="M000008-source">
|
150
|
+
<pre>
|
151
|
+
<span class="ruby-comment cmt"># File lib/yaml_store.rb, line 9</span>
|
152
|
+
9: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">file_location</span>)
|
153
|
+
10: <span class="ruby-keyword kw">super</span>(<span class="ruby-identifier">params_from_yaml</span>(<span class="ruby-identifier">file_location</span>))
|
154
|
+
11: <span class="ruby-ivar">@file_location</span> = <span class="ruby-identifier">file_location</span>
|
155
|
+
12: <span class="ruby-keyword kw">end</span>
|
156
|
+
</pre>
|
157
|
+
</div>
|
158
|
+
</div>
|
159
|
+
</div>
|
160
|
+
|
161
|
+
<h3 class="section-bar">Public Instance methods</h3>
|
162
|
+
|
163
|
+
<div id="method-M000009" class="method-detail">
|
164
|
+
<a name="M000009"></a>
|
165
|
+
|
166
|
+
<div class="method-heading">
|
167
|
+
<a href="#M000009" class="method-signature">
|
168
|
+
<span class="method-name">reload</span><span class="method-args">()</span>
|
169
|
+
</a>
|
170
|
+
</div>
|
171
|
+
|
172
|
+
<div class="method-description">
|
173
|
+
<p>
|
174
|
+
Re-reads the YAML file.
|
175
|
+
</p>
|
176
|
+
<p><a class="source-toggle" href="#"
|
177
|
+
onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
|
178
|
+
<div class="method-source-code" id="M000009-source">
|
179
|
+
<pre>
|
180
|
+
<span class="ruby-comment cmt"># File lib/yaml_store.rb, line 15</span>
|
181
|
+
15: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">reload</span>
|
182
|
+
16: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">file_location</span>
|
183
|
+
17: <span class="ruby-identifier">params_from_yaml</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">file_location</span>)
|
184
|
+
18: <span class="ruby-keyword kw">end</span>
|
185
|
+
19: <span class="ruby-keyword kw">end</span>
|
186
|
+
</pre>
|
187
|
+
</div>
|
188
|
+
</div>
|
189
|
+
</div>
|
190
|
+
|
191
|
+
|
192
|
+
</div>
|
193
|
+
|
194
|
+
|
195
|
+
</div>
|
196
|
+
|
197
|
+
|
198
|
+
<div id="validator-badges">
|
199
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
200
|
+
</div>
|
201
|
+
|
202
|
+
</body>
|
203
|
+
</html>
|
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="#M000017">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-M000017" class="method-detail">
|
106
|
+
<a name="M000017"></a>
|
107
107
|
|
108
108
|
<div class="method-heading">
|
109
|
-
<a href="#
|
109
|
+
<a href="#M000017" class="method-signature">
|
110
110
|
<span class="method-name">configatron</span><span class="method-args">(&block)</span>
|
111
111
|
</a>
|
112
112
|
</div>
|
@@ -120,8 +120,8 @@ Configatron::Configatron configure method and yield up a <a
|
|
120
120
|
href="Configatron/Store.html">Configatron::Store</a> object.
|
121
121
|
</p>
|
122
122
|
<p><a class="source-toggle" href="#"
|
123
|
-
onclick="toggleCode('
|
124
|
-
<div class="method-source-code" id="
|
123
|
+
onclick="toggleCode('M000017-source');return false;">[Source]</a></p>
|
124
|
+
<div class="method-source-code" id="M000017-source">
|
125
125
|
<pre>
|
126
126
|
<span class="ruby-comment cmt"># File lib/kernel.rb, line 6</span>
|
127
127
|
6: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">configatron</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
data/doc/created.rid
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
Thu, 04 Sep 2008 13:46:36 -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
|
59
|
+
<td>Thu Sep 04 11:15:39 -0400 2008</td>
|
60
60
|
</tr>
|
61
61
|
</table>
|
62
62
|
</div>
|
@@ -74,6 +74,7 @@
|
|
74
74
|
|
75
75
|
<div class="name-list">
|
76
76
|
singleton
|
77
|
+
yaml
|
77
78
|
</div>
|
78
79
|
</div>
|
79
80
|
|
data/doc/files/lib/store_rb.html
CHANGED
@@ -0,0 +1,101 @@
|
|
1
|
+
<?xml version="1.0" encoding="iso-8859-1"?>
|
2
|
+
<!DOCTYPE html
|
3
|
+
PUBLIC "-//W3C//DTD XHTML 1.0 Transitional//EN"
|
4
|
+
"http://www.w3.org/TR/xhtml1/DTD/xhtml1-transitional.dtd">
|
5
|
+
|
6
|
+
<html xmlns="http://www.w3.org/1999/xhtml" xml:lang="en" lang="en">
|
7
|
+
<head>
|
8
|
+
<title>File: yaml_store.rb</title>
|
9
|
+
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
|
+
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
+
<link rel="stylesheet" href="../.././rdoc-style.css" type="text/css" media="screen" />
|
12
|
+
<script type="text/javascript">
|
13
|
+
// <![CDATA[
|
14
|
+
|
15
|
+
function popupCode( url ) {
|
16
|
+
window.open(url, "Code", "resizable=yes,scrollbars=yes,toolbar=no,status=no,height=150,width=400")
|
17
|
+
}
|
18
|
+
|
19
|
+
function toggleCode( id ) {
|
20
|
+
if ( document.getElementById )
|
21
|
+
elem = document.getElementById( id );
|
22
|
+
else if ( document.all )
|
23
|
+
elem = eval( "document.all." + id );
|
24
|
+
else
|
25
|
+
return false;
|
26
|
+
|
27
|
+
elemStyle = elem.style;
|
28
|
+
|
29
|
+
if ( elemStyle.display != "block" ) {
|
30
|
+
elemStyle.display = "block"
|
31
|
+
} else {
|
32
|
+
elemStyle.display = "none"
|
33
|
+
}
|
34
|
+
|
35
|
+
return true;
|
36
|
+
}
|
37
|
+
|
38
|
+
// Make codeblocks hidden by default
|
39
|
+
document.writeln( "<style type=\"text/css\">div.method-source-code { display: none }</style>" )
|
40
|
+
|
41
|
+
// ]]>
|
42
|
+
</script>
|
43
|
+
|
44
|
+
</head>
|
45
|
+
<body>
|
46
|
+
|
47
|
+
|
48
|
+
|
49
|
+
<div id="fileHeader">
|
50
|
+
<h1>yaml_store.rb</h1>
|
51
|
+
<table class="header-table">
|
52
|
+
<tr class="top-aligned-row">
|
53
|
+
<td><strong>Path:</strong></td>
|
54
|
+
<td>lib/yaml_store.rb
|
55
|
+
</td>
|
56
|
+
</tr>
|
57
|
+
<tr class="top-aligned-row">
|
58
|
+
<td><strong>Last Update:</strong></td>
|
59
|
+
<td>Thu Sep 04 11:17:28 -0400 2008</td>
|
60
|
+
</tr>
|
61
|
+
</table>
|
62
|
+
</div>
|
63
|
+
<!-- banner header -->
|
64
|
+
|
65
|
+
<div id="bodyContent">
|
66
|
+
|
67
|
+
|
68
|
+
|
69
|
+
<div id="contextContent">
|
70
|
+
|
71
|
+
|
72
|
+
|
73
|
+
</div>
|
74
|
+
|
75
|
+
|
76
|
+
</div>
|
77
|
+
|
78
|
+
|
79
|
+
<!-- if includes -->
|
80
|
+
|
81
|
+
<div id="section">
|
82
|
+
|
83
|
+
|
84
|
+
|
85
|
+
|
86
|
+
|
87
|
+
|
88
|
+
|
89
|
+
|
90
|
+
<!-- if method_list -->
|
91
|
+
|
92
|
+
|
93
|
+
</div>
|
94
|
+
|
95
|
+
|
96
|
+
<div id="validator-badges">
|
97
|
+
<p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
|
98
|
+
</div>
|
99
|
+
|
100
|
+
</body>
|
101
|
+
</html>
|
data/doc/fr_class_index.html
CHANGED
@@ -23,6 +23,7 @@
|
|
23
23
|
<a href="classes/Configatron/Configuration.html">Configatron::Configuration</a><br />
|
24
24
|
<a href="classes/Configatron/Helpers.html">Configatron::Helpers</a><br />
|
25
25
|
<a href="classes/Configatron/Store.html">Configatron::Store</a><br />
|
26
|
+
<a href="classes/Configatron/YamlStore.html">Configatron::YamlStore</a><br />
|
26
27
|
<a href="classes/Kernel.html">Kernel</a><br />
|
27
28
|
</div>
|
28
29
|
</div>
|
data/doc/fr_file_index.html
CHANGED
@@ -26,6 +26,7 @@
|
|
26
26
|
<a href="files/lib/helpers_rb.html">lib/helpers.rb</a><br />
|
27
27
|
<a href="files/lib/kernel_rb.html">lib/kernel.rb</a><br />
|
28
28
|
<a href="files/lib/store_rb.html">lib/store.rb</a><br />
|
29
|
+
<a href="files/lib/yaml_store_rb.html">lib/yaml_store.rb</a><br />
|
29
30
|
</div>
|
30
31
|
</div>
|
31
32
|
</body>
|
data/doc/fr_method_index.html
CHANGED
@@ -20,19 +20,23 @@
|
|
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#
|
24
|
-
<a href="classes/Configatron/Configuration.html#
|
25
|
-
<a href="classes/Configatron/Configuration.html#
|
23
|
+
<a href="classes/Kernel.html#M000017">configatron (Kernel)</a><br />
|
24
|
+
<a href="classes/Configatron/Configuration.html#M000010">configure (Configatron::Configuration)</a><br />
|
25
|
+
<a href="classes/Configatron/Configuration.html#M000011">configure_from_hash (Configatron::Configuration)</a><br />
|
26
|
+
<a href="classes/Configatron/Configuration.html#M000012">configure_from_yaml (Configatron::Configuration)</a><br />
|
26
27
|
<a href="classes/Configatron/Store.html#M000005">exists? (Configatron::Store)</a><br />
|
27
28
|
<a href="classes/Configatron/Helpers.html#M000001">exists? (Configatron::Helpers)</a><br />
|
28
29
|
<a href="classes/Configatron/Store.html#M000004">method_missing (Configatron::Store)</a><br />
|
29
30
|
<a href="classes/Configatron/Store.html#M000006">namespace (Configatron::Store)</a><br />
|
31
|
+
<a href="classes/Configatron/YamlStore.html#M000008">new (Configatron::YamlStore)</a><br />
|
30
32
|
<a href="classes/Configatron/Store.html#M000003">new (Configatron::Store)</a><br />
|
31
|
-
<a href="classes/Configatron/
|
32
|
-
<a href="classes/Configatron/Configuration.html#
|
33
|
-
<a href="classes/Configatron/
|
33
|
+
<a href="classes/Configatron/Store.html#M000007">reload (Configatron::Store)</a><br />
|
34
|
+
<a href="classes/Configatron/Configuration.html#M000013">reload (Configatron::Configuration)</a><br />
|
35
|
+
<a href="classes/Configatron/YamlStore.html#M000009">reload (Configatron::YamlStore)</a><br />
|
36
|
+
<a href="classes/Configatron/Configuration.html#M000015">reset (Configatron::Configuration)</a><br />
|
37
|
+
<a href="classes/Configatron/Configuration.html#M000014">reset! (Configatron::Configuration)</a><br />
|
34
38
|
<a href="classes/Configatron/Helpers.html#M000002">retrieve (Configatron::Helpers)</a><br />
|
35
|
-
<a href="classes/Configatron/Configuration.html#
|
39
|
+
<a href="classes/Configatron/Configuration.html#M000016">revert (Configatron::Configuration)</a><br />
|
36
40
|
</div>
|
37
41
|
</div>
|
38
42
|
</body>
|
data/lib/configatron.rb
CHANGED
@@ -1,8 +1,10 @@
|
|
1
1
|
require 'singleton'
|
2
|
+
require 'yaml'
|
2
3
|
require File.join(File.dirname(__FILE__), 'helpers')
|
3
4
|
require File.join(File.dirname(__FILE__), 'kernel')
|
4
5
|
require File.join(File.dirname(__FILE__), 'configuration')
|
5
6
|
require File.join(File.dirname(__FILE__), 'store')
|
7
|
+
require File.join(File.dirname(__FILE__), 'yaml_store')
|
6
8
|
|
7
9
|
module Configatron # :nodoc:
|
8
10
|
end
|
data/lib/configuration.rb
CHANGED
@@ -31,9 +31,22 @@ module Configatron
|
|
31
31
|
load_methods(storage)
|
32
32
|
end
|
33
33
|
|
34
|
+
# Used to load configuration settings from a YAML file.
|
35
|
+
def configure_from_yaml(path)
|
36
|
+
begin
|
37
|
+
storage = Configatron::YamlStore.new(path)
|
38
|
+
@_storage_list << storage
|
39
|
+
load_methods(storage)
|
40
|
+
rescue Errno::ENOENT => e
|
41
|
+
puts e.message
|
42
|
+
# file doesn't exist.
|
43
|
+
end
|
44
|
+
end
|
45
|
+
|
34
46
|
# Replays the history of configurations.
|
35
47
|
def reload
|
36
48
|
@_storage_list.each do |storage|
|
49
|
+
storage.reload
|
37
50
|
load_methods(storage)
|
38
51
|
end
|
39
52
|
end
|
data/lib/store.rb
CHANGED
data/lib/yaml_store.rb
ADDED
@@ -0,0 +1,33 @@
|
|
1
|
+
require File.join(File.dirname(__FILE__), 'store')
|
2
|
+
module Configatron
|
3
|
+
# Used to store each of the 'sets' of configuration parameters that came from a YAML file.
|
4
|
+
class YamlStore < Configatron::Store
|
5
|
+
|
6
|
+
attr_accessor :file_location
|
7
|
+
|
8
|
+
# Takes the full path to the YAML file.
|
9
|
+
def initialize(file_location)
|
10
|
+
super(params_from_yaml(file_location))
|
11
|
+
@file_location = file_location
|
12
|
+
end
|
13
|
+
|
14
|
+
# Re-reads the YAML file.
|
15
|
+
def reload
|
16
|
+
if self.file_location
|
17
|
+
params_from_yaml(self.file_location)
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def params_from_yaml(file_location)
|
23
|
+
begin
|
24
|
+
@parameters = YAML.load(File.read(file_location))
|
25
|
+
return @parameters
|
26
|
+
rescue Errno::ENOENT => e
|
27
|
+
puts e
|
28
|
+
end
|
29
|
+
return {}
|
30
|
+
end
|
31
|
+
|
32
|
+
end
|
33
|
+
end
|
@@ -1,3 +1,4 @@
|
|
1
|
+
require 'fileutils'
|
1
2
|
require 'pathname'
|
2
3
|
require Pathname(__FILE__).dirname.expand_path.parent + 'spec_helper'
|
3
4
|
|
@@ -29,6 +30,66 @@ describe Configatron::Configuration do
|
|
29
30
|
|
30
31
|
end
|
31
32
|
|
33
|
+
describe "configure_from_yaml" do
|
34
|
+
|
35
|
+
before :each do
|
36
|
+
configatron.reset!
|
37
|
+
@futurama = File.join(File.dirname(__FILE__), 'futurama.yml')
|
38
|
+
FileUtils.rm_f(@futurama)
|
39
|
+
end
|
40
|
+
|
41
|
+
after :each do
|
42
|
+
FileUtils.rm_f(@futurama)
|
43
|
+
end
|
44
|
+
|
45
|
+
it "should take a path to YAML file and use it configure configatron" do
|
46
|
+
configatron.should_not respond_to(:family_guy)
|
47
|
+
configatron.should_not respond_to(:lois)
|
48
|
+
|
49
|
+
configatron.configure_from_yaml(File.join(File.dirname(__FILE__), 'family_guy.yml'))
|
50
|
+
|
51
|
+
configatron.should respond_to(:family_guy)
|
52
|
+
configatron.should respond_to(:lois)
|
53
|
+
|
54
|
+
configatron.family_guy.should == "Peter Griffin"
|
55
|
+
configatron.lois.should == "Lois Griffin"
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should silently file if the file doesn't exist" do
|
59
|
+
lambda {configatron.configure_from_yaml(File.join(File.dirname(__FILE__), 'i_dont_exist.yml'))}.should_not raise_error(Errno::ENOENT)
|
60
|
+
end
|
61
|
+
|
62
|
+
it "should re-read the file during a reload" do
|
63
|
+
File.open(@futurama, 'w') do |f|
|
64
|
+
f.puts 'bender: robot'
|
65
|
+
f.puts 'fry: human'
|
66
|
+
end
|
67
|
+
|
68
|
+
configatron.should_not respond_to(:bender)
|
69
|
+
configatron.should_not respond_to(:fry)
|
70
|
+
|
71
|
+
configatron.configure_from_yaml(@futurama)
|
72
|
+
|
73
|
+
configatron.should respond_to(:bender)
|
74
|
+
configatron.should respond_to(:fry)
|
75
|
+
|
76
|
+
configatron.bender.should == 'robot'
|
77
|
+
configatron.fry.should == 'human'
|
78
|
+
|
79
|
+
File.open(@futurama, 'w') do |f|
|
80
|
+
f.puts 'bender: Bending Robot'
|
81
|
+
f.puts 'fry: Human Male'
|
82
|
+
end
|
83
|
+
|
84
|
+
configatron.reload
|
85
|
+
|
86
|
+
configatron.bender.should == 'Bending Robot'
|
87
|
+
configatron.fry.should == 'Human Male'
|
88
|
+
|
89
|
+
end
|
90
|
+
|
91
|
+
end
|
92
|
+
|
32
93
|
describe "revert" do
|
33
94
|
|
34
95
|
it "should roll back 1 level by default" do
|
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: 1.0
|
4
|
+
version: 1.1.0
|
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-09-04 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -27,10 +27,12 @@ files:
|
|
27
27
|
- lib/helpers.rb
|
28
28
|
- lib/kernel.rb
|
29
29
|
- lib/store.rb
|
30
|
+
- lib/yaml_store.rb
|
30
31
|
- README
|
31
32
|
- doc/classes/Configatron/Configuration.html
|
32
33
|
- doc/classes/Configatron/Helpers.html
|
33
34
|
- doc/classes/Configatron/Store.html
|
35
|
+
- doc/classes/Configatron/YamlStore.html
|
34
36
|
- doc/classes/Kernel.html
|
35
37
|
- doc/created.rid
|
36
38
|
- doc/files/lib/configatron_rb.html
|
@@ -38,6 +40,7 @@ files:
|
|
38
40
|
- doc/files/lib/helpers_rb.html
|
39
41
|
- doc/files/lib/kernel_rb.html
|
40
42
|
- doc/files/lib/store_rb.html
|
43
|
+
- doc/files/lib/yaml_store_rb.html
|
41
44
|
- doc/files/README.html
|
42
45
|
- doc/fr_class_index.html
|
43
46
|
- doc/fr_file_index.html
|
@@ -76,6 +79,7 @@ test_files:
|
|
76
79
|
- spec/spec_helper.rb
|
77
80
|
- spec/unit
|
78
81
|
- spec/unit/configuration_spec.rb
|
82
|
+
- spec/unit/family_guy.yml
|
79
83
|
- spec/unit/helpers_spec.rb
|
80
84
|
- spec/unit/kernel_spec.rb
|
81
85
|
- spec/unit/store_spec.rb
|