configatron 1.2.2 → 2.0.0

Sign up to get free protection for your applications and to get access to all the features.
Files changed (37) hide show
  1. data/README +61 -34
  2. data/doc/classes/Configatron.html +241 -0
  3. data/doc/classes/Configatron/ProtectedParameter.html +146 -0
  4. data/doc/classes/Configatron/Store.html +241 -121
  5. data/doc/classes/Kernel.html +13 -20
  6. data/doc/created.rid +1 -1
  7. data/doc/files/README.html +85 -43
  8. data/doc/files/lib/configatron/{configuration_rb.html → configatron_rb.html} +11 -4
  9. data/doc/files/lib/configatron/{helpers_rb.html → errors_rb.html} +4 -4
  10. data/doc/files/lib/configatron/kernel_rb.html +1 -1
  11. data/doc/files/lib/configatron/store_rb.html +1 -1
  12. data/doc/files/lib/configatron_rb.html +1 -2
  13. data/doc/fr_class_index.html +2 -4
  14. data/doc/fr_file_index.html +2 -3
  15. data/doc/fr_method_index.html +15 -21
  16. data/lib/configatron.rb +5 -44
  17. data/lib/configatron/configatron.rb +44 -0
  18. data/lib/configatron/errors.rb +7 -0
  19. data/lib/configatron/kernel.rb +3 -9
  20. data/lib/configatron/store.rb +148 -56
  21. data/spec/lib/configatron_spec.rb +293 -0
  22. data/spec/lib/futurama.yml +6 -0
  23. data/spec/spec_helper.rb +3 -2
  24. metadata +11 -18
  25. data/doc/classes/Configatron/Configuration.html +0 -402
  26. data/doc/classes/Configatron/Helpers.html +0 -174
  27. data/doc/classes/Configatron/YamlStore.html +0 -203
  28. data/doc/classes/Hash.html +0 -193
  29. data/doc/files/lib/configatron/yaml_store_rb.html +0 -101
  30. data/lib/configatron/configuration.rb +0 -112
  31. data/lib/configatron/helpers.rb +0 -27
  32. data/lib/configatron/yaml_store.rb +0 -33
  33. data/spec/unit/configuration_spec.rb +0 -299
  34. data/spec/unit/family_guy.yml +0 -2
  35. data/spec/unit/helpers_spec.rb +0 -115
  36. data/spec/unit/kernel_spec.rb +0 -48
  37. data/spec/unit/store_spec.rb +0 -91
data/README CHANGED
@@ -5,28 +5,24 @@ Configatron makes configuring your applications and scripts incredibly easy. No
5
5
  ==Examples
6
6
 
7
7
  ===Simple
8
- configatron do |config|
9
- config.email = "mark@mackframework.com"
10
- config.database_url = "postgres://localhost/mack_framework_rocks"
11
- # etc...
12
- end
8
+ configatron.email = 'me@example.com'
9
+ configatron.database_url = "postgres://localhost/mack_framework_rocks"
13
10
 
14
11
  Now, anywhere in your code you can do the following:
15
12
 
16
- configatron.email # => "mark@mackframework.com"
13
+ configatron.email # => "me@example.com"
17
14
  configatron.database_url # => "postgres://localhost/mack_framework_rocks"
18
15
 
19
16
  Viola! Simple as can be.
20
17
 
21
18
  Now you're saying, what if I want to have a 'default' set of options, but then override them later, based on other information? Simple again. Let's use our above example. We've configured our 'database_url' option to be "postgres://localhost/mack_framework_rocks". The problem with that is that is our production database url, not our development url. Fair enough, all you have to do is redeclare it:
22
19
 
23
- configatron do |config|
24
- config.database_url = "postgres://localhost/mack_framework_rocks_development"
25
- end
20
+ configatron.database_url = "postgres://localhost/mack_framework_rocks_development"
21
+
26
22
 
27
23
  becomes:
28
24
 
29
- configatron.email # => "mark@mackframework.com"
25
+ configatron.email # => "me@example.com"
30
26
  configatron.database_url # => "postgres://localhost/mack_framework_rocks_development"
31
27
 
32
28
  Notice how our other configuration parameters haven't changed? Cool, eh?
@@ -49,23 +45,12 @@ When the 'reload' method is called on configatron then the YAML file will be re-
49
45
  ===Namespaces
50
46
 
51
47
  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.
52
-
53
- configatron do |config|
54
- config.website_url = "http://www.mackframework.com"
55
- config.namespace(:email) do |email|
56
- email.namespace(:pop) do |pop|
57
- pop.address = "pop.example.com"
58
- pop.port = "110"
59
- # etc ...
60
- end
61
- email.namespace(:smtp) do |smtp|
62
- smtp.address = "smtp.example.com"
63
- smtp.port = "25"
64
- # etc ...
65
- end
66
- end
67
- # etc...
68
- end
48
+
49
+ configatron.website_url = "http://www.mackframework.com"
50
+ configatron.email.pop.address = "pop.example.com"
51
+ configatron.email.pop.port = 110
52
+ configatron.email.smtp.address = "smtp.example.com"
53
+ configatron.email.smtp.port = 25
69
54
 
70
55
  becomes:
71
56
 
@@ -77,16 +62,58 @@ Configatron allows you to nest namespaces to your hearts content! Just keep goin
77
62
 
78
63
  Of course you can update a single parameter n levels deep as well:
79
64
 
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
65
+ configatron.email.pop.address = "pop2.example.com"
87
66
 
88
67
  configatron.email.pop.address # => "pop2.example.com"
89
68
  configatron.email.smtp.address # => "smtp.example.com"
69
+
70
+ ===Misc.
71
+
72
+ Even if parameters haven't been set, you can still call them, and you'll get nil back:
73
+
74
+ configatron.i.dont.exist.nil? # => true
75
+ configatron.i.dont.exist # => nil
76
+
77
+ You can set 'default' values for parameters. If there is already a setting, it won't be replaced. This is useful if you've already done your 'configuration' and you call a library, that needs to have parameters set. The library can set it's defaults, without worrying that it might have overridden your custom settings.
78
+
79
+ configatron.set_default(:name, 'Mark Bates')
80
+ configatron.name # => 'Mark Bates'
81
+ configatron.set_default(:name, 'Me')
82
+ configatron.name # => 'Mark Bates'
83
+
84
+ Sometimes in testing, or other situations, you want to temporarily change some settings. You can do this with the <tt>temp</tt> method:
85
+
86
+ configatron.one = 1
87
+ configatron.letters.a = 'A'
88
+ configatron.letters.b = 'B'
89
+ configatron.temp do
90
+ configatron.letters.b = 'bb'
91
+ configatron.letters.c = 'c'
92
+ configatron.one # => 1
93
+ configatron.letters.a # => 'A'
94
+ configatron.letters.b # => 'bb'
95
+ configatron.letters.c # => 'c'
96
+ end
97
+ configatron.one # => 1
98
+ configatron.letters.a # => 'A'
99
+ configatron.letters.b # => 'B'
100
+ configatron.letters.c # => nil
101
+
102
+ You can also pass in an optional Hash to the <tt>temp</tt>:
103
+
104
+ configatron.one = 1
105
+ configatron.letters.a = 'A'
106
+ configatron.letters.b = 'B'
107
+ configatron.temp(:letters => {:b => 'bb', :c => 'c'}) do
108
+ configatron.one == 1
109
+ configatron.letters.a # => 'A'
110
+ configatron.letters.b # => 'bb'
111
+ configatron.letters.c # => 'c'
112
+ end
113
+ configatron.one == 1
114
+ configatron.letters.a # => 'A'
115
+ configatron.letters.b # => 'B'
116
+ configatron.letters.c # => nil
90
117
 
91
118
  Enjoy!
92
119
 
@@ -0,0 +1,241 @@
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</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</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../files/lib/configatron/configatron_rb.html">
59
+ lib/configatron/configatron.rb
60
+ </a>
61
+ <br />
62
+ <a href="../files/lib/configatron/errors_rb.html">
63
+ lib/configatron/errors.rb
64
+ </a>
65
+ <br />
66
+ <a href="../files/lib/configatron/store_rb.html">
67
+ lib/configatron/store.rb
68
+ </a>
69
+ <br />
70
+ </td>
71
+ </tr>
72
+
73
+ <tr class="top-aligned-row">
74
+ <td><strong>Parent:</strong></td>
75
+ <td>
76
+ Object
77
+ </td>
78
+ </tr>
79
+ </table>
80
+ </div>
81
+ <!-- banner header -->
82
+
83
+ <div id="bodyContent">
84
+
85
+
86
+
87
+ <div id="contextContent">
88
+
89
+
90
+
91
+ </div>
92
+
93
+ <div id="method-list">
94
+ <h3 class="section-bar">Methods</h3>
95
+
96
+ <div class="name-list">
97
+ <a href="#M000001">method_missing</a>&nbsp;&nbsp;
98
+ <a href="#M000002">reset!</a>&nbsp;&nbsp;
99
+ <a href="#M000003">temp</a>&nbsp;&nbsp;
100
+ </div>
101
+ </div>
102
+
103
+ </div>
104
+
105
+
106
+ <!-- if includes -->
107
+ <div id="includes">
108
+ <h3 class="section-bar">Included Modules</h3>
109
+
110
+ <div id="includes-list">
111
+ <span class="include-name">Singleton</span>
112
+ </div>
113
+ </div>
114
+
115
+ <div id="section">
116
+
117
+ <div id="class-list">
118
+ <h3 class="section-bar">Classes and Modules</h3>
119
+
120
+ Class <a href="Configatron/ProtectedParameter.html" class="link">Configatron::ProtectedParameter</a><br />
121
+ Class <a href="Configatron/Store.html" class="link">Configatron::Store</a><br />
122
+
123
+ </div>
124
+
125
+
126
+
127
+
128
+
129
+
130
+
131
+ <!-- if method_list -->
132
+ <div id="methods">
133
+ <h3 class="section-bar">Public Instance methods</h3>
134
+
135
+ <div id="method-M000001" class="method-detail">
136
+ <a name="M000001"></a>
137
+
138
+ <div class="method-heading">
139
+ <a href="#M000001" class="method-signature">
140
+ <span class="method-name">method_missing</span><span class="method-args">(sym, *args)</span>
141
+ </a>
142
+ </div>
143
+
144
+ <div class="method-description">
145
+ <p>
146
+ Forwards the method call onto the &#8216;namespaced&#8217; <a
147
+ href="Configatron/Store.html">Configatron::Store</a>
148
+ </p>
149
+ <p><a class="source-toggle" href="#"
150
+ onclick="toggleCode('M000001-source');return false;">[Source]</a></p>
151
+ <div class="method-source-code" id="M000001-source">
152
+ <pre>
153
+ <span class="ruby-comment cmt"># File lib/configatron/configatron.rb, line 12</span>
154
+ 12: <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>)
155
+ 13: <span class="ruby-ivar">@_store</span>[<span class="ruby-ivar">@_namespace</span>].<span class="ruby-identifier">send</span>(<span class="ruby-identifier">sym</span>, <span class="ruby-operator">*</span><span class="ruby-identifier">args</span>)
156
+ 14: <span class="ruby-keyword kw">end</span>
157
+ </pre>
158
+ </div>
159
+ </div>
160
+ </div>
161
+
162
+ <div id="method-M000002" class="method-detail">
163
+ <a name="M000002"></a>
164
+
165
+ <div class="method-heading">
166
+ <a href="#M000002" class="method-signature">
167
+ <span class="method-name">reset!</span><span class="method-args">()</span>
168
+ </a>
169
+ </div>
170
+
171
+ <div class="method-description">
172
+ <p>
173
+ Removes ALL configuration parameters
174
+ </p>
175
+ <p><a class="source-toggle" href="#"
176
+ onclick="toggleCode('M000002-source');return false;">[Source]</a></p>
177
+ <div class="method-source-code" id="M000002-source">
178
+ <pre>
179
+ <span class="ruby-comment cmt"># File lib/configatron/configatron.rb, line 17</span>
180
+ 17: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">reset!</span>
181
+ 18: <span class="ruby-ivar">@_store</span> = {<span class="ruby-identifier">:default</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-constant">Configatron</span><span class="ruby-operator">::</span><span class="ruby-constant">Store</span>.<span class="ruby-identifier">new</span>}
182
+ 19: <span class="ruby-keyword kw">end</span>
183
+ </pre>
184
+ </div>
185
+ </div>
186
+ </div>
187
+
188
+ <div id="method-M000003" class="method-detail">
189
+ <a name="M000003"></a>
190
+
191
+ <div class="method-heading">
192
+ <a href="#M000003" class="method-signature">
193
+ <span class="method-name">temp</span><span class="method-args">(options = nil) {|| ...}</span>
194
+ </a>
195
+ </div>
196
+
197
+ <div class="method-description">
198
+ <p>
199
+ Allows for the temporary overriding of parameters in a block. Takes an
200
+ optional Hash of parameters that will be applied before the block gets
201
+ called. At the end of the block, the temporary settings are deleted and the
202
+ original settings are reinstated.
203
+ </p>
204
+ <p><a class="source-toggle" href="#"
205
+ onclick="toggleCode('M000003-source');return false;">[Source]</a></p>
206
+ <div class="method-source-code" id="M000003-source">
207
+ <pre>
208
+ <span class="ruby-comment cmt"># File lib/configatron/configatron.rb, line 25</span>
209
+ 25: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">temp</span>(<span class="ruby-identifier">options</span> = <span class="ruby-keyword kw">nil</span>)
210
+ 26: <span class="ruby-ivar">@_namespace</span> = <span class="ruby-identifier">rand</span>
211
+ 27: <span class="ruby-ivar">@_store</span>[<span class="ruby-ivar">@_namespace</span>] = <span class="ruby-ivar">@_store</span>[<span class="ruby-identifier">:default</span>].<span class="ruby-identifier">deep_clone</span>
212
+ 28: <span class="ruby-keyword kw">begin</span>
213
+ 29: <span class="ruby-keyword kw">if</span> <span class="ruby-identifier">options</span>
214
+ 30: <span class="ruby-keyword kw">self</span>.<span class="ruby-identifier">method_missing</span>(<span class="ruby-identifier">:configure_from_hash</span>, <span class="ruby-identifier">options</span>)
215
+ 31: <span class="ruby-keyword kw">end</span>
216
+ 32: <span class="ruby-keyword kw">yield</span>
217
+ 33: <span class="ruby-keyword kw">rescue</span> <span class="ruby-constant">Exception</span> =<span class="ruby-operator">&gt;</span> <span class="ruby-identifier">e</span>
218
+ 34: <span class="ruby-identifier">raise</span> <span class="ruby-identifier">e</span>
219
+ 35: <span class="ruby-keyword kw">ensure</span>
220
+ 36: <span class="ruby-ivar">@_store</span>.<span class="ruby-identifier">delete</span>(<span class="ruby-ivar">@_namespace</span>)
221
+ 37: <span class="ruby-ivar">@_namespace</span> = <span class="ruby-identifier">:default</span>
222
+ 38: <span class="ruby-keyword kw">end</span>
223
+ 39: <span class="ruby-keyword kw">end</span>
224
+ </pre>
225
+ </div>
226
+ </div>
227
+ </div>
228
+
229
+
230
+ </div>
231
+
232
+
233
+ </div>
234
+
235
+
236
+ <div id="validator-badges">
237
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
238
+ </div>
239
+
240
+ </body>
241
+ </html>
@@ -0,0 +1,146 @@
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::ProtectedParameter</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::ProtectedParameter</td>
54
+ </tr>
55
+ <tr class="top-aligned-row">
56
+ <td><strong>In:</strong></td>
57
+ <td>
58
+ <a href="../../files/lib/configatron/errors_rb.html">
59
+ lib/configatron/errors.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
+ StandardError
69
+ </td>
70
+ </tr>
71
+ </table>
72
+ </div>
73
+ <!-- banner header -->
74
+
75
+ <div id="bodyContent">
76
+
77
+
78
+
79
+ <div id="contextContent">
80
+
81
+
82
+
83
+ </div>
84
+
85
+ <div id="method-list">
86
+ <h3 class="section-bar">Methods</h3>
87
+
88
+ <div class="name-list">
89
+ <a href="#M000014">intialize</a>&nbsp;&nbsp;
90
+ </div>
91
+ </div>
92
+
93
+ </div>
94
+
95
+
96
+ <!-- if includes -->
97
+
98
+ <div id="section">
99
+
100
+
101
+
102
+
103
+
104
+
105
+
106
+
107
+ <!-- if method_list -->
108
+ <div id="methods">
109
+ <h3 class="section-bar">Public Instance methods</h3>
110
+
111
+ <div id="method-M000014" class="method-detail">
112
+ <a name="M000014"></a>
113
+
114
+ <div class="method-heading">
115
+ <a href="#M000014" class="method-signature">
116
+ <span class="method-name">intialize</span><span class="method-args">(name)</span>
117
+ </a>
118
+ </div>
119
+
120
+ <div class="method-description">
121
+ <p><a class="source-toggle" href="#"
122
+ onclick="toggleCode('M000014-source');return false;">[Source]</a></p>
123
+ <div class="method-source-code" id="M000014-source">
124
+ <pre>
125
+ <span class="ruby-comment cmt"># File lib/configatron/errors.rb, line 3</span>
126
+ 3: <span class="ruby-keyword kw">def</span> <span class="ruby-identifier">intialize</span>(<span class="ruby-identifier">name</span>)
127
+ 4: <span class="ruby-keyword kw">super</span>(<span class="ruby-node">&quot;Can not modify protected parameter: '#{name}'&quot;</span>)
128
+ 5: <span class="ruby-keyword kw">end</span>
129
+ </pre>
130
+ </div>
131
+ </div>
132
+ </div>
133
+
134
+
135
+ </div>
136
+
137
+
138
+ </div>
139
+
140
+
141
+ <div id="validator-badges">
142
+ <p><small><a href="http://validator.w3.org/check/referer">[Validate]</a></small></p>
143
+ </div>
144
+
145
+ </body>
146
+ </html>