configatron 1.1.0 → 1.2.0
Sign up to get free protection for your applications and to get access to all the features.
- data/README +28 -0
- data/doc/classes/Configatron/Configuration.html +9 -9
- data/doc/classes/Configatron/Helpers.html +4 -4
- data/doc/classes/Configatron/Store.html +42 -35
- data/doc/classes/Configatron/YamlStore.html +4 -4
- data/doc/classes/Kernel.html +3 -3
- data/doc/created.rid +1 -1
- data/doc/files/README.html +38 -1
- data/doc/files/lib/{configuration_rb.html → configatron/configuration_rb.html} +3 -3
- data/doc/files/lib/{helpers_rb.html → configatron/helpers_rb.html} +3 -3
- data/doc/files/lib/{kernel_rb.html → configatron/kernel_rb.html} +3 -3
- data/doc/files/lib/{store_rb.html → configatron/store_rb.html} +3 -3
- data/doc/files/lib/{yaml_store_rb.html → configatron/yaml_store_rb.html} +3 -3
- data/doc/files/lib/configatron_rb.html +1 -1
- data/doc/fr_file_index.html +5 -5
- data/lib/{configuration.rb → configatron/configuration.rb} +3 -0
- data/lib/{helpers.rb → configatron/helpers.rb} +0 -0
- data/lib/{kernel.rb → configatron/kernel.rb} +0 -0
- data/lib/{store.rb → configatron/store.rb} +8 -1
- data/lib/{yaml_store.rb → configatron/yaml_store.rb} +0 -0
- data/lib/configatron.rb +6 -5
- data/spec/unit/configuration_spec.rb +57 -1
- metadata +12 -12
data/README
CHANGED
@@ -31,6 +31,21 @@ becomes:
|
|
31
31
|
|
32
32
|
Notice how our other configuration parameters haven't changed? Cool, eh?
|
33
33
|
|
34
|
+
===Hash/YAML
|
35
|
+
You can configure configatron from a hash as well:
|
36
|
+
|
37
|
+
configatron.configure_from_hash({:email => {:pop => {:address => 'pop.example.com', :port => 110}}, :smtp => {:address => 'smtp.example.com'}})
|
38
|
+
|
39
|
+
configatron.email.pop.address # => 'pop.example.com'
|
40
|
+
configatron.email.pop.port # => 110
|
41
|
+
# and so on...
|
42
|
+
|
43
|
+
Notice how they're all namespaced for your as well. The same holds true for YAML files:
|
44
|
+
|
45
|
+
configuration.configure_from_yaml('/path/to/file.yml')
|
46
|
+
|
47
|
+
When the 'reload' method is called on configatron then the YAML file will be re-read in case changes have been made.
|
48
|
+
|
34
49
|
===Namespaces
|
35
50
|
|
36
51
|
The question that should be on your lips is what I need to have namespaced configuration parameters. It's easy! Configatron allows you to create namespaces.
|
@@ -60,6 +75,19 @@ becomes:
|
|
60
75
|
|
61
76
|
Configatron allows you to nest namespaces to your hearts content! Just keep going, it's that easy.
|
62
77
|
|
78
|
+
Of course you can update a single parameter n levels deep as well:
|
79
|
+
|
80
|
+
configatron do |config|
|
81
|
+
config.namespace(:email) do |email|
|
82
|
+
email.namespace(:pop) do |pop|
|
83
|
+
pop.address = "pop2.example.com"
|
84
|
+
end
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
configatron.email.pop.address # => "pop2.example.com"
|
89
|
+
configatron.email.smtp.address # => "smtp.example.com"
|
90
|
+
|
63
91
|
Enjoy!
|
64
92
|
|
65
93
|
==Contact
|
@@ -55,8 +55,8 @@
|
|
55
55
|
<tr class="top-aligned-row">
|
56
56
|
<td><strong>In:</strong></td>
|
57
57
|
<td>
|
58
|
-
<a href="../../files/lib/configuration_rb.html">
|
59
|
-
lib/configuration.rb
|
58
|
+
<a href="../../files/lib/configatron/configuration_rb.html">
|
59
|
+
lib/configatron/configuration.rb
|
60
60
|
</a>
|
61
61
|
<br />
|
62
62
|
</td>
|
@@ -163,7 +163,7 @@ Yields a new <a href="Store.html">Configatron::Store</a> class.
|
|
163
163
|
onclick="toggleCode('M000010-source');return false;">[Source]</a></p>
|
164
164
|
<div class="method-source-code" id="M000010-source">
|
165
165
|
<pre>
|
166
|
-
<span class="ruby-comment cmt"># File lib/configuration.rb, line 18</span>
|
166
|
+
<span class="ruby-comment cmt"># File lib/configatron/configuration.rb, line 18</span>
|
167
167
|
18: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">configure</span>
|
168
168
|
19: <span class="ruby-identifier">storage</span> = <span class="ruby-constant">Configatron</span><span class="ruby-operator">::</span><span class="ruby-constant">Store</span>.<span class="ruby-identifier">new</span>
|
169
169
|
20: <span class="ruby-keyword kw">yield</span> <span class="ruby-identifier">storage</span>
|
@@ -194,7 +194,7 @@ Used to load configuration settings from a Hash.
|
|
194
194
|
onclick="toggleCode('M000011-source');return false;">[Source]</a></p>
|
195
195
|
<div class="method-source-code" id="M000011-source">
|
196
196
|
<pre>
|
197
|
-
<span class="ruby-comment cmt"># File lib/configuration.rb, line 28</span>
|
197
|
+
<span class="ruby-comment cmt"># File lib/configatron/configuration.rb, line 28</span>
|
198
198
|
28: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">configure_from_hash</span>(<span class="ruby-identifier">parameters</span>)
|
199
199
|
29: <span class="ruby-identifier">storage</span> = <span class="ruby-constant">Configatron</span><span class="ruby-operator">::</span><span class="ruby-constant">Store</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">parameters</span>)
|
200
200
|
30: <span class="ruby-ivar">@_storage_list</span> <span class="ruby-operator"><<</span> <span class="ruby-identifier">storage</span>
|
@@ -222,7 +222,7 @@ Used to load configuration settings from a YAML file.
|
|
222
222
|
onclick="toggleCode('M000012-source');return false;">[Source]</a></p>
|
223
223
|
<div class="method-source-code" id="M000012-source">
|
224
224
|
<pre>
|
225
|
-
<span class="ruby-comment cmt"># File lib/configuration.rb, line 35</span>
|
225
|
+
<span class="ruby-comment cmt"># File lib/configatron/configuration.rb, line 35</span>
|
226
226
|
35: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">configure_from_yaml</span>(<span class="ruby-identifier">path</span>)
|
227
227
|
36: <span class="ruby-keyword kw">begin</span>
|
228
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>)
|
@@ -255,7 +255,7 @@ Replays the history of configurations.
|
|
255
255
|
onclick="toggleCode('M000013-source');return false;">[Source]</a></p>
|
256
256
|
<div class="method-source-code" id="M000013-source">
|
257
257
|
<pre>
|
258
|
-
<span class="ruby-comment cmt"># File lib/configuration.rb, line 47</span>
|
258
|
+
<span class="ruby-comment cmt"># File lib/configatron/configuration.rb, line 47</span>
|
259
259
|
47: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">reload</span>
|
260
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
261
|
49: <span class="ruby-identifier">storage</span>.<span class="ruby-identifier">reload</span>
|
@@ -284,7 +284,7 @@ All methods are undefined.
|
|
284
284
|
onclick="toggleCode('M000015-source');return false;">[Source]</a></p>
|
285
285
|
<div class="method-source-code" id="M000015-source">
|
286
286
|
<pre>
|
287
|
-
<span class="ruby-comment cmt"># File lib/configuration.rb, line 64</span>
|
287
|
+
<span class="ruby-comment cmt"># File lib/configatron/configuration.rb, line 64</span>
|
288
288
|
64: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">reset</span>
|
289
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
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>
|
@@ -323,7 +323,7 @@ to false.
|
|
323
323
|
onclick="toggleCode('M000014-source');return false;">[Source]</a></p>
|
324
324
|
<div class="method-source-code" id="M000014-source">
|
325
325
|
<pre>
|
326
|
-
<span class="ruby-comment cmt"># File lib/configuration.rb, line 57</span>
|
326
|
+
<span class="ruby-comment cmt"># File lib/configatron/configuration.rb, line 57</span>
|
327
327
|
57: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">reset!</span>
|
328
328
|
58: <span class="ruby-identifier">reset</span>
|
329
329
|
59: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">nil_for_missing</span> = <span class="ruby-keyword kw">false</span>
|
@@ -351,7 +351,7 @@ Peels back n number of configuration parameters.
|
|
351
351
|
onclick="toggleCode('M000016-source');return false;">[Source]</a></p>
|
352
352
|
<div class="method-source-code" id="M000016-source">
|
353
353
|
<pre>
|
354
|
-
<span class="ruby-comment cmt"># File lib/configuration.rb, line 78</span>
|
354
|
+
<span class="ruby-comment cmt"># File lib/configatron/configuration.rb, line 78</span>
|
355
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
356
|
79: <span class="ruby-identifier">reset</span>
|
357
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>}
|
@@ -55,8 +55,8 @@
|
|
55
55
|
<tr class="top-aligned-row">
|
56
56
|
<td><strong>In:</strong></td>
|
57
57
|
<td>
|
58
|
-
<a href="../../files/lib/helpers_rb.html">
|
59
|
-
lib/helpers.rb
|
58
|
+
<a href="../../files/lib/configatron/helpers_rb.html">
|
59
|
+
lib/configatron/helpers.rb
|
60
60
|
</a>
|
61
61
|
<br />
|
62
62
|
</td>
|
@@ -120,7 +120,7 @@ Checks whether or not configuration parameter exists.
|
|
120
120
|
onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
|
121
121
|
<div class="method-source-code" id="M000001-source">
|
122
122
|
<pre>
|
123
|
-
<span class="ruby-comment cmt"># File lib/helpers.rb, line 5</span>
|
123
|
+
<span class="ruby-comment cmt"># File lib/configatron/helpers.rb, line 5</span>
|
124
124
|
5: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">exists?</span>(<span class="ruby-identifier">name</span>)
|
125
125
|
6: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">respond_to?</span>(<span class="ruby-identifier">name</span>)
|
126
126
|
7: <span class="ruby-keyword kw">end</span>
|
@@ -148,7 +148,7 @@ exist.
|
|
148
148
|
onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
|
149
149
|
<div class="method-source-code" id="M000002-source">
|
150
150
|
<pre>
|
151
|
-
<span class="ruby-comment cmt"># File lib/helpers.rb, line 20</span>
|
151
|
+
<span class="ruby-comment cmt"># File lib/configatron/helpers.rb, line 20</span>
|
152
152
|
20: <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-constant">ArgumentError</span>)
|
153
153
|
21: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">name</span>) <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">exists?</span>(<span class="ruby-identifier">name</span>)
|
154
154
|
22: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">default_value</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">default_value</span> <span class="ruby-operator">==</span> <span class="ruby-constant">ArgumentError</span>
|
@@ -55,8 +55,8 @@
|
|
55
55
|
<tr class="top-aligned-row">
|
56
56
|
<td><strong>In:</strong></td>
|
57
57
|
<td>
|
58
|
-
<a href="../../files/lib/store_rb.html">
|
59
|
-
lib/store.rb
|
58
|
+
<a href="../../files/lib/configatron/store_rb.html">
|
59
|
+
lib/configatron/store.rb
|
60
60
|
</a>
|
61
61
|
<br />
|
62
62
|
</td>
|
@@ -158,10 +158,14 @@ Takes an optional Hash to configure parameters.
|
|
158
158
|
onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
|
159
159
|
<div class="method-source-code" id="M000003-source">
|
160
160
|
<pre>
|
161
|
-
<span class="ruby-comment cmt"># File lib/store.rb, line 10</span>
|
161
|
+
<span class="ruby-comment cmt"># File lib/configatron/store.rb, line 10</span>
|
162
162
|
10: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">parameters</span> = {})
|
163
|
-
11: <span class="ruby-ivar">@parameters</span> = <span class="ruby-identifier">parameters</span>
|
164
|
-
12:
|
163
|
+
11: <span class="ruby-ivar">@parameters</span> = <span class="ruby-identifier">parameters</span>.<span class="ruby-identifier">inject</span>({}) <span class="ruby-keyword kw">do</span> <span class="ruby-operator">|</span><span class="ruby-identifier">m</span>,<span class="ruby-identifier">pair</span><span class="ruby-operator">|</span>
|
164
|
+
12: <span class="ruby-identifier">sym</span> = <span class="ruby-identifier">pair</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">is_a?</span>(<span class="ruby-constant">Symbol</span>) <span class="ruby-operator">?</span> <span class="ruby-identifier">pair</span>.<span class="ruby-identifier">first</span> <span class="ruby-operator">:</span> <span class="ruby-identifier">pair</span>.<span class="ruby-identifier">first</span>.<span class="ruby-identifier">intern</span>
|
165
|
+
13: <span class="ruby-identifier">m</span>[<span class="ruby-identifier">sym</span>] = <span class="ruby-identifier">pair</span>.<span class="ruby-identifier">last</span>
|
166
|
+
14: <span class="ruby-identifier">m</span>
|
167
|
+
15: <span class="ruby-keyword kw">end</span>
|
168
|
+
16: <span class="ruby-keyword kw">end</span>
|
165
169
|
</pre>
|
166
170
|
</div>
|
167
171
|
</div>
|
@@ -186,11 +190,11 @@ Checks whether or not configuration parameter exists.
|
|
186
190
|
onclick="toggleCode('M000005-source');return false;">[Source]</a></p>
|
187
191
|
<div class="method-source-code" id="M000005-source">
|
188
192
|
<pre>
|
189
|
-
<span class="ruby-comment cmt"># File lib/store.rb, line
|
190
|
-
|
191
|
-
|
192
|
-
|
193
|
-
|
193
|
+
<span class="ruby-comment cmt"># File lib/configatron/store.rb, line 37</span>
|
194
|
+
37: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">exists?</span>(<span class="ruby-identifier">name</span>)
|
195
|
+
38: <span class="ruby-keyword kw">return</span> <span class="ruby-keyword kw">true</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-ivar">@parameters</span>[<span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_sym</span>].<span class="ruby-identifier">nil?</span>
|
196
|
+
39: <span class="ruby-keyword kw">super</span>(<span class="ruby-identifier">name</span>)
|
197
|
+
40: <span class="ruby-keyword kw">end</span>
|
194
198
|
</pre>
|
195
199
|
</div>
|
196
200
|
</div>
|
@@ -217,16 +221,19 @@ from the parameters hash is returned, if it exists.
|
|
217
221
|
onclick="toggleCode('M000004-source');return false;">[Source]</a></p>
|
218
222
|
<div class="method-source-code" id="M000004-source">
|
219
223
|
<pre>
|
220
|
-
<span class="ruby-comment cmt"># File lib/store.rb, line
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
224
|
+
<span class="ruby-comment cmt"># File lib/configatron/store.rb, line 23</span>
|
225
|
+
23: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">method_missing</span>(<span class="ruby-identifier">sym</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
|
226
|
+
24: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">sym</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">match</span>(<span class="ruby-regexp re">/(.+)=$/</span>)
|
227
|
+
25: <span class="ruby-ivar">@parameters</span>[<span class="ruby-identifier">sym</span>.<span class="ruby-identifier">to_s</span>.<span class="ruby-identifier">gsub</span>(<span class="ruby-value str">"="</span>, <span class="ruby-value str">''</span>).<span class="ruby-identifier">to_sym</span>] = <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>
|
228
|
+
26: <span class="ruby-keyword kw">else</span>
|
229
|
+
27: <span class="ruby-identifier">val</span> = <span class="ruby-ivar">@parameters</span>[<span class="ruby-identifier">sym</span>]
|
230
|
+
28: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">val</span>.<span class="ruby-identifier">is_a?</span> <span class="ruby-constant">Hash</span>
|
231
|
+
29: <span class="ruby-identifier">val</span> = (<span class="ruby-ivar">@parameters</span>[<span class="ruby-identifier">sym</span>] = <span class="ruby-constant">Configatron</span><span class="ruby-operator">::</span><span class="ruby-constant">Store</span>.<span class="ruby-identifier">new</span>(<span class="ruby-identifier">val</span>))
|
232
|
+
30: <span class="ruby-keyword kw">end</span>
|
233
|
+
31: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">val</span> <span class="ruby-keyword kw">unless</span> <span class="ruby-identifier">val</span>.<span class="ruby-identifier">nil?</span>
|
234
|
+
32: <span class="ruby-keyword kw">return</span> <span class="ruby-identifier">handle_missing_parameter</span>(<span class="ruby-identifier">sym</span>)
|
235
|
+
33: <span class="ruby-keyword kw">end</span>
|
236
|
+
34: <span class="ruby-keyword kw">end</span>
|
230
237
|
</pre>
|
231
238
|
</div>
|
232
239
|
</div>
|
@@ -250,18 +257,18 @@ parameters.
|
|
250
257
|
onclick="toggleCode('M000006-source');return false;">[Source]</a></p>
|
251
258
|
<div class="method-source-code" id="M000006-source">
|
252
259
|
<pre>
|
253
|
-
<span class="ruby-comment cmt"># File lib/store.rb, line
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
260
|
+
<span class="ruby-comment cmt"># File lib/configatron/store.rb, line 43</span>
|
261
|
+
43: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">namespace</span>(<span class="ruby-identifier">name</span>)
|
262
|
+
44: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">exists?</span>(<span class="ruby-identifier">name</span>)
|
263
|
+
45: <span class="ruby-keyword kw">yield</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_sym</span>)
|
264
|
+
46: <span class="ruby-keyword kw">elsif</span> <span class="ruby-identifier">configatron</span>.<span class="ruby-identifier">exists?</span>(<span class="ruby-identifier">name</span>)
|
265
|
+
47: <span class="ruby-keyword kw">yield</span> <span class="ruby-identifier">configatron</span>.<span class="ruby-identifier">send</span>(<span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_sym</span>)
|
266
|
+
48: <span class="ruby-keyword kw">else</span>
|
267
|
+
49: <span class="ruby-identifier">ns</span> = <span class="ruby-constant">Configatron</span><span class="ruby-operator">::</span><span class="ruby-constant">Store</span>.<span class="ruby-identifier">new</span>
|
268
|
+
50: <span class="ruby-keyword kw">yield</span> <span class="ruby-identifier">ns</span>
|
269
|
+
51: <span class="ruby-ivar">@parameters</span>[<span class="ruby-identifier">name</span>.<span class="ruby-identifier">to_sym</span>] = <span class="ruby-identifier">ns</span>
|
270
|
+
52: <span class="ruby-keyword kw">end</span>
|
271
|
+
53: <span class="ruby-keyword kw">end</span>
|
265
272
|
</pre>
|
266
273
|
</div>
|
267
274
|
</div>
|
@@ -286,9 +293,9 @@ etc…
|
|
286
293
|
onclick="toggleCode('M000007-source');return false;">[Source]</a></p>
|
287
294
|
<div class="method-source-code" id="M000007-source">
|
288
295
|
<pre>
|
289
|
-
<span class="ruby-comment cmt"># File lib/store.rb, line
|
290
|
-
|
291
|
-
|
296
|
+
<span class="ruby-comment cmt"># File lib/configatron/store.rb, line 57</span>
|
297
|
+
57: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">reload</span>
|
298
|
+
58: <span class="ruby-keyword kw">end</span>
|
292
299
|
</pre>
|
293
300
|
</div>
|
294
301
|
</div>
|
@@ -55,8 +55,8 @@
|
|
55
55
|
<tr class="top-aligned-row">
|
56
56
|
<td><strong>In:</strong></td>
|
57
57
|
<td>
|
58
|
-
<a href="../../files/lib/yaml_store_rb.html">
|
59
|
-
lib/yaml_store.rb
|
58
|
+
<a href="../../files/lib/configatron/yaml_store_rb.html">
|
59
|
+
lib/configatron/yaml_store.rb
|
60
60
|
</a>
|
61
61
|
<br />
|
62
62
|
</td>
|
@@ -148,7 +148,7 @@ Takes the full path to the YAML file.
|
|
148
148
|
onclick="toggleCode('M000008-source');return false;">[Source]</a></p>
|
149
149
|
<div class="method-source-code" id="M000008-source">
|
150
150
|
<pre>
|
151
|
-
<span class="ruby-comment cmt"># File lib/yaml_store.rb, line 9</span>
|
151
|
+
<span class="ruby-comment cmt"># File lib/configatron/yaml_store.rb, line 9</span>
|
152
152
|
9: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">initialize</span>(<span class="ruby-identifier">file_location</span>)
|
153
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
154
|
11: <span class="ruby-ivar">@file_location</span> = <span class="ruby-identifier">file_location</span>
|
@@ -177,7 +177,7 @@ Re-reads the YAML file.
|
|
177
177
|
onclick="toggleCode('M000009-source');return false;">[Source]</a></p>
|
178
178
|
<div class="method-source-code" id="M000009-source">
|
179
179
|
<pre>
|
180
|
-
<span class="ruby-comment cmt"># File lib/yaml_store.rb, line 15</span>
|
180
|
+
<span class="ruby-comment cmt"># File lib/configatron/yaml_store.rb, line 15</span>
|
181
181
|
15: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">reload</span>
|
182
182
|
16: <span class="ruby-keyword kw">if</span> <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">file_location</span>
|
183
183
|
17: <span class="ruby-identifier">params_from_yaml</span>(<span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">file_location</span>)
|
data/doc/classes/Kernel.html
CHANGED
@@ -55,8 +55,8 @@
|
|
55
55
|
<tr class="top-aligned-row">
|
56
56
|
<td><strong>In:</strong></td>
|
57
57
|
<td>
|
58
|
-
<a href="../files/lib/kernel_rb.html">
|
59
|
-
lib/kernel.rb
|
58
|
+
<a href="../files/lib/configatron/kernel_rb.html">
|
59
|
+
lib/configatron/kernel.rb
|
60
60
|
</a>
|
61
61
|
<br />
|
62
62
|
</td>
|
@@ -123,7 +123,7 @@ href="Configatron/Store.html">Configatron::Store</a> object.
|
|
123
123
|
onclick="toggleCode('M000017-source');return false;">[Source]</a></p>
|
124
124
|
<div class="method-source-code" id="M000017-source">
|
125
125
|
<pre>
|
126
|
-
<span class="ruby-comment cmt"># File lib/kernel.rb, line 6</span>
|
126
|
+
<span class="ruby-comment cmt"># File lib/configatron/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>)
|
128
128
|
7: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">block_given?</span>
|
129
129
|
8: <span class="ruby-constant">Configatron</span><span class="ruby-operator">::</span><span class="ruby-constant">Configuration</span>.<span class="ruby-identifier">instance</span>.<span class="ruby-identifier">configure</span>(<span class="ruby-operator">&</span><span class="ruby-identifier">block</span>)
|
data/doc/created.rid
CHANGED
@@ -1 +1 @@
|
|
1
|
-
|
1
|
+
Mon, 08 Sep 2008 15:54:51 -0400
|
data/doc/files/README.html
CHANGED
@@ -56,7 +56,7 @@
|
|
56
56
|
</tr>
|
57
57
|
<tr class="top-aligned-row">
|
58
58
|
<td><strong>Last Update:</strong></td>
|
59
|
-
<td>
|
59
|
+
<td>Mon Sep 08 15:54:42 -0400 2008</td>
|
60
60
|
</tr>
|
61
61
|
</table>
|
62
62
|
</div>
|
@@ -120,6 +120,28 @@ becomes:
|
|
120
120
|
Notice how our other configuration parameters haven‘t changed? Cool,
|
121
121
|
eh?
|
122
122
|
</p>
|
123
|
+
<h3>Hash/YAML</h3>
|
124
|
+
<p>
|
125
|
+
You can configure configatron from a hash as well:
|
126
|
+
</p>
|
127
|
+
<pre>
|
128
|
+
configatron.configure_from_hash({:email => {:pop => {:address => 'pop.example.com', :port => 110}}, :smtp => {:address => 'smtp.example.com'}})
|
129
|
+
|
130
|
+
configatron.email.pop.address # => 'pop.example.com'
|
131
|
+
configatron.email.pop.port # => 110
|
132
|
+
# and so on...
|
133
|
+
</pre>
|
134
|
+
<p>
|
135
|
+
Notice how they‘re all namespaced for your as well. The same holds
|
136
|
+
true for YAML files:
|
137
|
+
</p>
|
138
|
+
<pre>
|
139
|
+
configuration.configure_from_yaml('/path/to/file.yml')
|
140
|
+
</pre>
|
141
|
+
<p>
|
142
|
+
When the ‘reload’ method is called on configatron then the YAML
|
143
|
+
file will be re-read in case changes have been made.
|
144
|
+
</p>
|
123
145
|
<h3>Namespaces</h3>
|
124
146
|
<p>
|
125
147
|
The question that should be on your lips is what I need to have namespaced
|
@@ -157,6 +179,21 @@ Configatron allows you to nest namespaces to your hearts content! Just keep
|
|
157
179
|
going, it‘s that easy.
|
158
180
|
</p>
|
159
181
|
<p>
|
182
|
+
Of course you can update a single parameter n levels deep as well:
|
183
|
+
</p>
|
184
|
+
<pre>
|
185
|
+
configatron do |config|
|
186
|
+
config.namespace(:email) do |email|
|
187
|
+
email.namespace(:pop) do |pop|
|
188
|
+
pop.address = "pop2.example.com"
|
189
|
+
end
|
190
|
+
end
|
191
|
+
end
|
192
|
+
|
193
|
+
configatron.email.pop.address # => "pop2.example.com"
|
194
|
+
configatron.email.smtp.address # => "smtp.example.com"
|
195
|
+
</pre>
|
196
|
+
<p>
|
160
197
|
Enjoy!
|
161
198
|
</p>
|
162
199
|
<h2>Contact</h2>
|
@@ -8,7 +8,7 @@
|
|
8
8
|
<title>File: configuration.rb</title>
|
9
9
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
10
|
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
-
<link rel="stylesheet" href="
|
11
|
+
<link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
12
12
|
<script type="text/javascript">
|
13
13
|
// <![CDATA[
|
14
14
|
|
@@ -51,12 +51,12 @@
|
|
51
51
|
<table class="header-table">
|
52
52
|
<tr class="top-aligned-row">
|
53
53
|
<td><strong>Path:</strong></td>
|
54
|
-
<td>lib/configuration.rb
|
54
|
+
<td>lib/configatron/configuration.rb
|
55
55
|
</td>
|
56
56
|
</tr>
|
57
57
|
<tr class="top-aligned-row">
|
58
58
|
<td><strong>Last Update:</strong></td>
|
59
|
-
<td>
|
59
|
+
<td>Mon Sep 08 15:47:41 -0400 2008</td>
|
60
60
|
</tr>
|
61
61
|
</table>
|
62
62
|
</div>
|
@@ -8,7 +8,7 @@
|
|
8
8
|
<title>File: helpers.rb</title>
|
9
9
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
10
|
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
-
<link rel="stylesheet" href="
|
11
|
+
<link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
12
12
|
<script type="text/javascript">
|
13
13
|
// <![CDATA[
|
14
14
|
|
@@ -51,12 +51,12 @@
|
|
51
51
|
<table class="header-table">
|
52
52
|
<tr class="top-aligned-row">
|
53
53
|
<td><strong>Path:</strong></td>
|
54
|
-
<td>lib/helpers.rb
|
54
|
+
<td>lib/configatron/helpers.rb
|
55
55
|
</td>
|
56
56
|
</tr>
|
57
57
|
<tr class="top-aligned-row">
|
58
58
|
<td><strong>Last Update:</strong></td>
|
59
|
-
<td>
|
59
|
+
<td>Mon Sep 08 14:47:48 -0400 2008</td>
|
60
60
|
</tr>
|
61
61
|
</table>
|
62
62
|
</div>
|
@@ -8,7 +8,7 @@
|
|
8
8
|
<title>File: kernel.rb</title>
|
9
9
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
10
|
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
-
<link rel="stylesheet" href="
|
11
|
+
<link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
12
12
|
<script type="text/javascript">
|
13
13
|
// <![CDATA[
|
14
14
|
|
@@ -51,12 +51,12 @@
|
|
51
51
|
<table class="header-table">
|
52
52
|
<tr class="top-aligned-row">
|
53
53
|
<td><strong>Path:</strong></td>
|
54
|
-
<td>lib/kernel.rb
|
54
|
+
<td>lib/configatron/kernel.rb
|
55
55
|
</td>
|
56
56
|
</tr>
|
57
57
|
<tr class="top-aligned-row">
|
58
58
|
<td><strong>Last Update:</strong></td>
|
59
|
-
<td>
|
59
|
+
<td>Mon Sep 08 14:47:48 -0400 2008</td>
|
60
60
|
</tr>
|
61
61
|
</table>
|
62
62
|
</div>
|
@@ -8,7 +8,7 @@
|
|
8
8
|
<title>File: store.rb</title>
|
9
9
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
10
|
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
-
<link rel="stylesheet" href="
|
11
|
+
<link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
12
12
|
<script type="text/javascript">
|
13
13
|
// <![CDATA[
|
14
14
|
|
@@ -51,12 +51,12 @@
|
|
51
51
|
<table class="header-table">
|
52
52
|
<tr class="top-aligned-row">
|
53
53
|
<td><strong>Path:</strong></td>
|
54
|
-
<td>lib/store.rb
|
54
|
+
<td>lib/configatron/store.rb
|
55
55
|
</td>
|
56
56
|
</tr>
|
57
57
|
<tr class="top-aligned-row">
|
58
58
|
<td><strong>Last Update:</strong></td>
|
59
|
-
<td>
|
59
|
+
<td>Mon Sep 08 15:47:41 -0400 2008</td>
|
60
60
|
</tr>
|
61
61
|
</table>
|
62
62
|
</div>
|
@@ -8,7 +8,7 @@
|
|
8
8
|
<title>File: yaml_store.rb</title>
|
9
9
|
<meta http-equiv="Content-Type" content="text/html; charset=iso-8859-1" />
|
10
10
|
<meta http-equiv="Content-Script-Type" content="text/javascript" />
|
11
|
-
<link rel="stylesheet" href="
|
11
|
+
<link rel="stylesheet" href="../../.././rdoc-style.css" type="text/css" media="screen" />
|
12
12
|
<script type="text/javascript">
|
13
13
|
// <![CDATA[
|
14
14
|
|
@@ -51,12 +51,12 @@
|
|
51
51
|
<table class="header-table">
|
52
52
|
<tr class="top-aligned-row">
|
53
53
|
<td><strong>Path:</strong></td>
|
54
|
-
<td>lib/yaml_store.rb
|
54
|
+
<td>lib/configatron/yaml_store.rb
|
55
55
|
</td>
|
56
56
|
</tr>
|
57
57
|
<tr class="top-aligned-row">
|
58
58
|
<td><strong>Last Update:</strong></td>
|
59
|
-
<td>
|
59
|
+
<td>Mon Sep 08 14:47:48 -0400 2008</td>
|
60
60
|
</tr>
|
61
61
|
</table>
|
62
62
|
</div>
|
data/doc/fr_file_index.html
CHANGED
@@ -22,11 +22,11 @@
|
|
22
22
|
<div id="index-entries">
|
23
23
|
<a href="files/README.html">README</a><br />
|
24
24
|
<a href="files/lib/configatron_rb.html">lib/configatron.rb</a><br />
|
25
|
-
<a href="files/lib/configuration_rb.html">lib/configuration.rb</a><br />
|
26
|
-
<a href="files/lib/helpers_rb.html">lib/helpers.rb</a><br />
|
27
|
-
<a href="files/lib/kernel_rb.html">lib/kernel.rb</a><br />
|
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 />
|
25
|
+
<a href="files/lib/configatron/configuration_rb.html">lib/configatron/configuration.rb</a><br />
|
26
|
+
<a href="files/lib/configatron/helpers_rb.html">lib/configatron/helpers.rb</a><br />
|
27
|
+
<a href="files/lib/configatron/kernel_rb.html">lib/configatron/kernel.rb</a><br />
|
28
|
+
<a href="files/lib/configatron/store_rb.html">lib/configatron/store.rb</a><br />
|
29
|
+
<a href="files/lib/configatron/yaml_store_rb.html">lib/configatron/yaml_store.rb</a><br />
|
30
30
|
</div>
|
31
31
|
</div>
|
32
32
|
</body>
|
File without changes
|
File without changes
|
@@ -8,7 +8,11 @@ module Configatron
|
|
8
8
|
|
9
9
|
# Takes an optional Hash to configure parameters.
|
10
10
|
def initialize(parameters = {})
|
11
|
-
@parameters = parameters
|
11
|
+
@parameters = parameters.inject({}) do |m,pair|
|
12
|
+
sym = pair.first.is_a?(Symbol) ? pair.first : pair.first.intern
|
13
|
+
m[sym] = pair.last
|
14
|
+
m
|
15
|
+
end
|
12
16
|
end
|
13
17
|
|
14
18
|
# If a method is called with an = at the end, then that method name, minus
|
@@ -21,6 +25,9 @@ module Configatron
|
|
21
25
|
@parameters[sym.to_s.gsub("=", '').to_sym] = *args
|
22
26
|
else
|
23
27
|
val = @parameters[sym]
|
28
|
+
if val.is_a? Hash
|
29
|
+
val = (@parameters[sym] = Configatron::Store.new(val))
|
30
|
+
end
|
24
31
|
return val unless val.nil?
|
25
32
|
return handle_missing_parameter(sym)
|
26
33
|
end
|
File without changes
|
data/lib/configatron.rb
CHANGED
@@ -1,10 +1,11 @@
|
|
1
1
|
require 'singleton'
|
2
2
|
require 'yaml'
|
3
|
-
|
4
|
-
require File.join(File.dirname(__FILE__), '
|
5
|
-
require File.join(File.dirname(__FILE__), '
|
6
|
-
require File.join(File.dirname(__FILE__), '
|
7
|
-
require File.join(File.dirname(__FILE__), '
|
3
|
+
|
4
|
+
require File.join(File.dirname(__FILE__), 'configatron', 'helpers')
|
5
|
+
require File.join(File.dirname(__FILE__), 'configatron', 'kernel')
|
6
|
+
require File.join(File.dirname(__FILE__), 'configatron', 'configuration')
|
7
|
+
require File.join(File.dirname(__FILE__), 'configatron', 'store')
|
8
|
+
require File.join(File.dirname(__FILE__), 'configatron', 'yaml_store')
|
8
9
|
|
9
10
|
module Configatron # :nodoc:
|
10
11
|
end
|
@@ -30,6 +30,62 @@ describe Configatron::Configuration do
|
|
30
30
|
|
31
31
|
end
|
32
32
|
|
33
|
+
describe "hashes to namespace" 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 namespace hashes from yaml" do
|
46
|
+
|
47
|
+
configatron.should_not respond_to(:cartoon)
|
48
|
+
|
49
|
+
File.open(@futurama, 'w') do |f|
|
50
|
+
f.puts %{
|
51
|
+
cartoon:
|
52
|
+
characters:
|
53
|
+
fry: human
|
54
|
+
leela: mutant
|
55
|
+
bender: robot
|
56
|
+
transportation: space ship
|
57
|
+
fans:
|
58
|
+
one: Mark Bates
|
59
|
+
two: Dylan Bates
|
60
|
+
}
|
61
|
+
end
|
62
|
+
|
63
|
+
configatron.configure_from_yaml(@futurama)
|
64
|
+
|
65
|
+
configatron.should respond_to(:cartoon)
|
66
|
+
configatron.cartoon.should be_an_instance_of(Configatron::Store)
|
67
|
+
|
68
|
+
configatron.cartoon.characters.fry.should == 'human'
|
69
|
+
configatron.cartoon.transportation.should == 'space ship'
|
70
|
+
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should namespace hashes" do
|
74
|
+
|
75
|
+
configatron.should_not respond_to(:cartoon)
|
76
|
+
|
77
|
+
configatron.configure_from_hash({:cartoon => {:characters => {:fry => 'human', :leela => 'mutant', :bender => 'robot'}, :transportation => 'space ship'}, :fans => {:one => 'Mark Bates', :two => 'Dylan Bates'}})
|
78
|
+
|
79
|
+
configatron.should respond_to(:cartoon)
|
80
|
+
configatron.cartoon.should be_an_instance_of(Configatron::Store)
|
81
|
+
|
82
|
+
configatron.cartoon.characters.fry.should == 'human'
|
83
|
+
configatron.cartoon.transportation.should == 'space ship'
|
84
|
+
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
33
89
|
describe "configure_from_yaml" do
|
34
90
|
|
35
91
|
before :each do
|
@@ -55,7 +111,7 @@ describe Configatron::Configuration do
|
|
55
111
|
configatron.lois.should == "Lois Griffin"
|
56
112
|
end
|
57
113
|
|
58
|
-
it "should silently
|
114
|
+
it "should silently fail if the file doesn't exist" do
|
59
115
|
lambda {configatron.configure_from_yaml(File.join(File.dirname(__FILE__), 'i_dont_exist.yml'))}.should_not raise_error(Errno::ENOENT)
|
60
116
|
end
|
61
117
|
|
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.
|
4
|
+
version: 1.2.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-09-
|
12
|
+
date: 2008-09-08 00:00:00 -04:00
|
13
13
|
default_executable:
|
14
14
|
dependencies: []
|
15
15
|
|
@@ -22,12 +22,12 @@ extensions: []
|
|
22
22
|
extra_rdoc_files:
|
23
23
|
- README
|
24
24
|
files:
|
25
|
+
- lib/configatron/configuration.rb
|
26
|
+
- lib/configatron/helpers.rb
|
27
|
+
- lib/configatron/kernel.rb
|
28
|
+
- lib/configatron/store.rb
|
29
|
+
- lib/configatron/yaml_store.rb
|
25
30
|
- lib/configatron.rb
|
26
|
-
- lib/configuration.rb
|
27
|
-
- lib/helpers.rb
|
28
|
-
- lib/kernel.rb
|
29
|
-
- lib/store.rb
|
30
|
-
- lib/yaml_store.rb
|
31
31
|
- README
|
32
32
|
- doc/classes/Configatron/Configuration.html
|
33
33
|
- doc/classes/Configatron/Helpers.html
|
@@ -35,12 +35,12 @@ files:
|
|
35
35
|
- doc/classes/Configatron/YamlStore.html
|
36
36
|
- doc/classes/Kernel.html
|
37
37
|
- doc/created.rid
|
38
|
+
- doc/files/lib/configatron/configuration_rb.html
|
39
|
+
- doc/files/lib/configatron/helpers_rb.html
|
40
|
+
- doc/files/lib/configatron/kernel_rb.html
|
41
|
+
- doc/files/lib/configatron/store_rb.html
|
42
|
+
- doc/files/lib/configatron/yaml_store_rb.html
|
38
43
|
- doc/files/lib/configatron_rb.html
|
39
|
-
- doc/files/lib/configuration_rb.html
|
40
|
-
- doc/files/lib/helpers_rb.html
|
41
|
-
- doc/files/lib/kernel_rb.html
|
42
|
-
- doc/files/lib/store_rb.html
|
43
|
-
- doc/files/lib/yaml_store_rb.html
|
44
44
|
- doc/files/README.html
|
45
45
|
- doc/fr_class_index.html
|
46
46
|
- doc/fr_file_index.html
|