configatron 2.2.2 → 2.3.0

Sign up to get free protection for your applications and to get access to all the features.
data/doc/rdoc-style.css DELETED
@@ -1,208 +0,0 @@
1
-
2
- body {
3
- font-family: Verdana,Arial,Helvetica,sans-serif;
4
- font-size: 90%;
5
- margin: 0;
6
- margin-left: 40px;
7
- padding: 0;
8
- background: white;
9
- }
10
-
11
- h1,h2,h3,h4 { margin: 0; color: #efefef; background: transparent; }
12
- h1 { font-size: 150%; }
13
- h2,h3,h4 { margin-top: 1em; }
14
-
15
- a { background: #eef; color: #039; text-decoration: none; }
16
- a:hover { background: #039; color: #eef; }
17
-
18
- /* Override the base stylesheet's Anchor inside a table cell */
19
- td > a {
20
- background: transparent;
21
- color: #039;
22
- text-decoration: none;
23
- }
24
-
25
- /* and inside a section title */
26
- .section-title > a {
27
- background: transparent;
28
- color: #eee;
29
- text-decoration: none;
30
- }
31
-
32
- /* === Structural elements =================================== */
33
-
34
- div#index {
35
- margin: 0;
36
- margin-left: -40px;
37
- padding: 0;
38
- font-size: 90%;
39
- }
40
-
41
-
42
- div#index a {
43
- margin-left: 0.7em;
44
- }
45
-
46
- div#index .section-bar {
47
- margin-left: 0px;
48
- padding-left: 0.7em;
49
- background: #ccc;
50
- font-size: small;
51
- }
52
-
53
-
54
- div#classHeader, div#fileHeader {
55
- width: auto;
56
- color: white;
57
- padding: 0.5em 1.5em 0.5em 1.5em;
58
- margin: 0;
59
- margin-left: -40px;
60
- border-bottom: 3px solid #006;
61
- }
62
-
63
- div#classHeader a, div#fileHeader a {
64
- background: inherit;
65
- color: white;
66
- }
67
-
68
- div#classHeader td, div#fileHeader td {
69
- background: inherit;
70
- color: white;
71
- }
72
-
73
-
74
- div#fileHeader {
75
- background: #057;
76
- }
77
-
78
- div#classHeader {
79
- background: #048;
80
- }
81
-
82
-
83
- .class-name-in-header {
84
- font-size: 180%;
85
- font-weight: bold;
86
- }
87
-
88
-
89
- div#bodyContent {
90
- padding: 0 1.5em 0 1.5em;
91
- }
92
-
93
- div#description {
94
- padding: 0.5em 1.5em;
95
- background: #efefef;
96
- border: 1px dotted #999;
97
- }
98
-
99
- div#description h1,h2,h3,h4,h5,h6 {
100
- color: #125;;
101
- background: transparent;
102
- }
103
-
104
- div#validator-badges {
105
- text-align: center;
106
- }
107
- div#validator-badges img { border: 0; }
108
-
109
- div#copyright {
110
- color: #333;
111
- background: #efefef;
112
- font: 0.75em sans-serif;
113
- margin-top: 5em;
114
- margin-bottom: 0;
115
- padding: 0.5em 2em;
116
- }
117
-
118
-
119
- /* === Classes =================================== */
120
-
121
- table.header-table {
122
- color: white;
123
- font-size: small;
124
- }
125
-
126
- .type-note {
127
- font-size: small;
128
- color: #DEDEDE;
129
- }
130
-
131
- .xxsection-bar {
132
- background: #eee;
133
- color: #333;
134
- padding: 3px;
135
- }
136
-
137
- .section-bar {
138
- color: #333;
139
- border-bottom: 1px solid #999;
140
- margin-left: -20px;
141
- }
142
-
143
-
144
- .section-title {
145
- background: #79a;
146
- color: #eee;
147
- padding: 3px;
148
- margin-top: 2em;
149
- margin-left: -30px;
150
- border: 1px solid #999;
151
- }
152
-
153
- .top-aligned-row { vertical-align: top }
154
- .bottom-aligned-row { vertical-align: bottom }
155
-
156
- /* --- Context section classes ----------------------- */
157
-
158
- .context-row { }
159
- .context-item-name { font-family: monospace; font-weight: bold; color: black; }
160
- .context-item-value { font-size: small; color: #448; }
161
- .context-item-desc { color: #333; padding-left: 2em; }
162
-
163
- /* --- Method classes -------------------------- */
164
- .method-detail {
165
- background: #efefef;
166
- padding: 0;
167
- margin-top: 0.5em;
168
- margin-bottom: 1em;
169
- border: 1px dotted #ccc;
170
- }
171
- .method-heading {
172
- color: black;
173
- background: #ccc;
174
- border-bottom: 1px solid #666;
175
- padding: 0.2em 0.5em 0 0.5em;
176
- }
177
- .method-signature { color: black; background: inherit; }
178
- .method-name { font-weight: bold; }
179
- .method-args { font-style: italic; }
180
- .method-description { padding: 0 0.5em 0 0.5em; }
181
-
182
- /* --- Source code sections -------------------- */
183
-
184
- a.source-toggle { font-size: 90%; }
185
- div.method-source-code {
186
- background: #262626;
187
- color: #ffdead;
188
- margin: 1em;
189
- padding: 0.5em;
190
- border: 1px dashed #999;
191
- overflow: hidden;
192
- }
193
-
194
- div.method-source-code pre { color: #ffdead; overflow: hidden; }
195
-
196
- /* --- Ruby keyword styles --------------------- */
197
-
198
- .standalone-code { background: #221111; color: #ffdead; overflow: hidden; }
199
-
200
- .ruby-constant { color: #7fffd4; background: transparent; }
201
- .ruby-keyword { color: #00ffff; background: transparent; }
202
- .ruby-ivar { color: #eedd82; background: transparent; }
203
- .ruby-operator { color: #00ffee; background: transparent; }
204
- .ruby-identifier { color: #ffdead; background: transparent; }
205
- .ruby-node { color: #ffa07a; background: transparent; }
206
- .ruby-comment { color: #b22222; font-weight: bold; background: transparent; }
207
- .ruby-regexp { color: #ffa07a; background: transparent; }
208
- .ruby-value { color: #7fffd4; background: transparent; }
@@ -1,28 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
-
3
- configatron.foo.bar = :bar
4
- configatron.a.b.c.d = 'D'
5
-
6
- class Foo
7
- end
8
-
9
- module A
10
- module B
11
- class C
12
- end
13
- end
14
- end
15
-
16
- describe Class do
17
-
18
- describe 'to_configatron' do
19
-
20
- it 'should return a Configatron::Store object based on the name of the class' do
21
- Foo.to_configatron.should be_kind_of(Configatron::Store)
22
- Foo.to_configatron.bar.should == :bar
23
- A::B::C.to_configatron.d.should == 'D'
24
- end
25
-
26
- end
27
-
28
- end
@@ -1,434 +0,0 @@
1
- require File.join(File.dirname(__FILE__), '..', 'spec_helper')
2
-
3
- describe "configatron" do
4
-
5
- before(:each) do
6
- configatron.reset!
7
- end
8
-
9
- describe 'protect' do
10
-
11
- it 'should protect a parameter and prevent it from being set' do
12
- configatron.one = 1
13
- configatron.protect(:one)
14
- lambda{configatron.one = 'one'}.should raise_error(Configatron::ProtectedParameter)
15
- configatron.one.should == 1
16
- end
17
-
18
- it 'should protect basic methods' do
19
- lambda{configatron.object_id = 123456}.should raise_error(Configatron::ProtectedParameter)
20
- lambda{configatron.foo.object_id = 123456}.should raise_error(Configatron::ProtectedParameter)
21
- end
22
-
23
- it 'should work with nested parameters' do
24
- configatron.one = 1
25
- configatron.letters.a = 'A'
26
- configatron.letters.b = 'B'
27
- configatron.letters.protect(:a)
28
- lambda{configatron.letters.a = 'a'}.should raise_error(Configatron::ProtectedParameter)
29
- configatron.letters.a.should == 'A'
30
- configatron.protect(:letters)
31
- lambda{configatron.letters.a = 'a'}.should raise_error(Configatron::ProtectedParameter)
32
- lambda{configatron.letters = 'letter'}.should raise_error(Configatron::ProtectedParameter)
33
- end
34
-
35
- it 'should work with configure_from_hash' do
36
- configatron.one = 1
37
- configatron.letters.a = 'A'
38
- configatron.letters.b = 'B'
39
- configatron.letters.protect(:a)
40
- lambda{configatron.configure_from_hash(:letters => {:a => 'a'})}.should raise_error(Configatron::ProtectedParameter)
41
- configatron.letters.a.should == 'A'
42
- configatron.protect(:letters)
43
- lambda{configatron.letters.configure_from_hash(:a => 'a')}.should raise_error(Configatron::ProtectedParameter)
44
- lambda{configatron.configure_from_hash(:letters => 'letters')}.should raise_error(Configatron::ProtectedParameter)
45
- end
46
-
47
- it "should be able to protect all parameters at once" do
48
- configatron.one = 1
49
- configatron.letters.a = 'A'
50
- configatron.letters.b = 'B'
51
- configatron.protect_all!
52
- [:a,:b].each do |l|
53
- lambda{configatron.configure_from_hash(:letters => {l => l.to_s})}.should raise_error(Configatron::ProtectedParameter)
54
- configatron.letters.send(l).should == l.to_s.upcase
55
- end
56
- lambda{configatron.letters.configure_from_hash(:a => 'a')}.should raise_error(Configatron::ProtectedParameter)
57
- lambda{configatron.configure_from_hash(:letters => 'letters')}.should raise_error(Configatron::ProtectedParameter)
58
- end
59
-
60
- it "should be able to unprotect a parameter" do
61
- configatron.one = 1
62
- configatron.protect(:one)
63
- configatron.unprotect(:one)
64
- lambda{configatron.one = 2}.should_not raise_error
65
- end
66
-
67
- it "should be able to unprotect all parameters at once" do
68
- configatron.one = 1
69
- configatron.letters.a = 'A'
70
- configatron.letters.b = 'B'
71
- configatron.protect_all!
72
- configatron.unprotect_all!
73
- lambda{configatron.one = 2}.should_not raise_error
74
- lambda{configatron.letters.configure_from_hash(:a => 'a')}.should_not raise_error
75
- end
76
-
77
- end
78
-
79
- describe 'lock' do
80
- before :each do
81
- configatron.letters.a = 'A'
82
- configatron.letters.b = 'B'
83
- configatron.letters.greek.alpha = 'alpha'
84
- configatron.lock(:letters)
85
- end
86
-
87
- it 'should allow setting of existing parameters in locked parameter' do
88
- lambda { configatron.letters.a = 'a' }.should_not raise_error
89
- end
90
-
91
- it 'should not allow setting of a parameter that is not already set' do
92
- lambda { configatron.letters.c = 'C' }.should raise_error(Configatron::LockedNamespace)
93
- end
94
-
95
- it 'should allow setting of existing parameters in child of locked parameter' do
96
- lambda { configatron.letters.greek.alpha = 'a' }.should_not raise_error
97
- end
98
-
99
- it 'should not allow setting of new parameters in child of locked parameter' do
100
- lambda { configatron.letters.greek.beta = 'beta' }.should raise_error(Configatron::LockedNamespace)
101
- end
102
-
103
- it 'should not affect parameters below the locked namespace' do
104
- lambda { configatron.one = 1 }.should_not raise_error
105
- end
106
-
107
- it 'should raise an ArgumentError if unknown namespace is locked' do
108
- lambda { configatron.lock(:numbers).should raise_error(ArgumentError) }
109
- end
110
-
111
- describe 'then unlock' do
112
- before :each do
113
- configatron.unlock(:letters)
114
- end
115
-
116
- it 'should allow setting of new parameter in unlocked namespace' do
117
- lambda { configatron.letters.d = 'd' }.should_not raise_error
118
- end
119
-
120
- it 'should allow setting of new parameter in unlocked namespace\'s child' do
121
- lambda { configatron.letters.greek.zeta = 'z' }.should_not raise_error
122
- end
123
-
124
- it 'should raise an ArgumentError if unknown namespace is unlocked' do
125
- lambda { configatron.unlock(:numbers).should raise_error(ArgumentError) }
126
- end
127
- end
128
- end
129
-
130
- describe 'temp' do
131
-
132
- it 'should revert back to the original parameters when the block ends' do
133
- configatron.one = 1
134
- configatron.letters.a = 'A'
135
- configatron.letters.b = 'B'
136
- configatron.temp do
137
- configatron.letters.b = 'bb'
138
- configatron.letters.c = 'c'
139
- configatron.one.should == 1
140
- configatron.letters.a.should == 'A'
141
- configatron.letters.b.should == 'bb'
142
- configatron.letters.c.should == 'c'
143
- end
144
- configatron.one.should == 1
145
- configatron.letters.a.should == 'A'
146
- configatron.letters.b.should == 'B'
147
- configatron.letters.c.should be_nil
148
- end
149
-
150
- it 'should take an optional hash of parameters' do
151
- configatron.one = 1
152
- configatron.letters.a = 'A'
153
- configatron.letters.b = 'B'
154
- configatron.temp(:letters => {:b => 'bb', :c => 'c'}) do
155
- configatron.one.should == 1
156
- configatron.letters.a.should == 'A'
157
- configatron.letters.b.should == 'bb'
158
- configatron.letters.c.should == 'c'
159
- end
160
- configatron.one.should == 1
161
- configatron.letters.a.should == 'A'
162
- configatron.letters.b.should == 'B'
163
- configatron.letters.c.should be_nil
164
- end
165
-
166
- it 'should work the same as temp_start/temp_end' do
167
- configatron.one = 1
168
- configatron.temp_start
169
- configatron.one = 'ONE'
170
- configatron.one.should == 'ONE'
171
- configatron.temp_end
172
- configatron.one.should == 1
173
- end
174
-
175
- it 'should be able to nest' do
176
- configatron.one = 1
177
- configatron.letters.a = 'A'
178
- configatron.letters.b = 'B'
179
- configatron.temp do
180
- configatron.letters.b = 'bb'
181
- configatron.letters.c = 'c'
182
- configatron.one.should == 1
183
- configatron.letters.a.should == 'A'
184
- configatron.letters.b.should == 'bb'
185
- configatron.letters.c.should == 'c'
186
- configatron.temp do
187
- configatron.letters.b = 'bbb'
188
- configatron.one.should == 1
189
- configatron.letters.a.should == 'A'
190
- configatron.letters.b.should == 'bbb'
191
- configatron.letters.c.should == 'c'
192
- end
193
- end
194
- configatron.one.should == 1
195
- configatron.letters.a.should == 'A'
196
- configatron.letters.b.should == 'B'
197
- configatron.letters.c.should be_nil
198
- end
199
-
200
- end
201
-
202
- describe 'configure_from_hash' do
203
-
204
- it 'should configure itself from a hash' do
205
- configatron.foo.should be_nil
206
- configatron.configure_from_hash(:foo => :bar)
207
- configatron.foo.should == :bar
208
- end
209
-
210
- it 'should handled deeply nested params' do
211
- configatron.friends.rachel.should be_nil
212
- configatron.configure_from_hash(:friends => {:rachel => 'Rachel Green'})
213
- configatron.friends.rachel.should == 'Rachel Green'
214
- end
215
-
216
- it 'should not remove previously defined params' do
217
- configatron.friends.rachel = 'Rachel Green'
218
- configatron.friends.ross = 'Ross Gellar'
219
- configatron.friends.monica = 'Monica Gellar'
220
- configatron.configure_from_hash(:friends => {:rachel => 'R. Green', :monica => 'Monica Bing'})
221
- configatron.friends.ross.should == 'Ross Gellar'
222
- configatron.friends.rachel.should == 'R. Green'
223
- configatron.friends.monica.should == 'Monica Bing'
224
- end
225
-
226
- end
227
-
228
- describe 'configure_from_yaml' do
229
-
230
- it 'should configure itself from a yaml file' do
231
- configatron.futurama.should be_nil
232
- configatron.configure_from_yaml(File.join(File.dirname(__FILE__), 'futurama.yml'))
233
- configatron.futurama.robots.bender.should == 'Bender The Robot'
234
- end
235
-
236
- it 'should not remove previously defined params' do
237
- configatron.futurama.mutants.leela = 'Leela'
238
- configatron.configure_from_yaml(File.join(File.dirname(__FILE__), 'futurama.yml'))
239
- configatron.futurama.robots.bender.should == 'Bender The Robot'
240
- configatron.futurama.mutants.leela = 'Leela'
241
- end
242
-
243
- it "should fail silently if the file doesn't exist" do
244
- lambda{configatron.configure_from_yaml('i_dont_exist.yml')}.should_not raise_error
245
- end
246
-
247
- it "should be able to load a specific hash from the file" do
248
- configatron.others.should be_nil
249
- configatron.survivors.should be_nil
250
- configatron.configure_from_yaml(File.join(File.dirname(__FILE__), 'lost.yml'), :hash => "survivors")
251
- configatron.others.should be_nil
252
- configatron.survivors.should be_nil
253
- configatron.on_island.jack.should == 'Jack Shepherd'
254
- end
255
-
256
- end
257
-
258
- it 'should return a parameter' do
259
- configatron.foo = :bar
260
- configatron.foo.should == :bar
261
- end
262
-
263
- it 'should return a nested parameter' do
264
- configatron.children.dylan = 'Dylan Bates'
265
- configatron.children.dylan.should == 'Dylan Bates'
266
- end
267
-
268
- it 'should set a nested parameter and not remove previously defined params' do
269
- configatron.friends.rachel = 'Rachel Green'
270
- configatron.friends.rachel.should == 'Rachel Green'
271
- configatron.friends.ross = 'Ross Gellar'
272
- configatron.friends.ross.should == 'Ross Gellar'
273
- configatron.friends.monica = 'Monica Gellar'
274
- configatron.friends.monica.should == 'Monica Gellar'
275
- configatron.friends.rachel = 'R. Green'
276
- configatron.friends.monica = 'Monica Bing'
277
- configatron.friends.rachel.should == 'R. Green'
278
- configatron.friends.ross.should == 'Ross Gellar'
279
- configatron.friends.monica.should == 'Monica Bing'
280
- end
281
-
282
- it 'should return the Configatron instance' do
283
- configatron.should be_is_a(Configatron)
284
- end
285
-
286
- describe 'to_hash' do
287
-
288
- it 'should return a hash of all the params' do
289
- configatron.one = 1
290
- configatron.letters.a = 'A'
291
- configatron.letters.b = 'B'
292
- configatron.to_hash.should == {:one => 1, :letters => {:a => 'A', :b => 'B'}}
293
- end
294
-
295
- end
296
-
297
- describe 'inspect' do
298
-
299
- it 'should call return the inspect method of the to_hash method' do
300
- configatron.one = 1
301
- configatron.letters.a = 'A'
302
- configatron.letters.b = 'B'
303
- configatron.numbers.small.one = 1
304
- configatron.numbers.small.others = [2,3]
305
- configatron.numbers.big.one.hundred = '100'
306
-
307
- configatron.inspect.should == %{
308
- configatron.letters.a = "A"
309
- configatron.letters.b = "B"
310
- configatron.numbers.big.one.hundred = "100"
311
- configatron.numbers.small.one = 1
312
- configatron.numbers.small.others = [2, 3]
313
- configatron.one = 1
314
- }.strip
315
-
316
- end
317
-
318
- end
319
-
320
- describe 'nil?' do
321
-
322
- it 'should return true if there are no parameters' do
323
- configatron.should be_nil
324
- configatron.friends.should be_nil
325
- end
326
-
327
- it 'should return true if there are no parameters on a nested parameter' do
328
- configatron.friends.monica.should be_nil
329
- end
330
-
331
- end
332
-
333
- describe 'retrieve' do
334
-
335
- it 'should retrieve a parameter' do
336
- configatron.office = 'Michael'
337
- configatron.retrieve(:office).should == 'Michael'
338
- end
339
-
340
- it 'should return the optional second parameter if the config setting is nil' do
341
- configatron.retrieve(:office, 'Stanley').should == 'Stanley'
342
- end
343
-
344
- it 'should work with a symbol or a string' do
345
- configatron.office = 'Michael'
346
- configatron.retrieve(:office).should == 'Michael'
347
- configatron.retrieve('office').should == 'Michael'
348
- end
349
-
350
- it 'should work on nested parameters' do
351
- configatron.the.office = 'Michael'
352
- configatron.the.retrieve(:office).should == 'Michael'
353
- configatron.the.retrieve('office').should == 'Michael'
354
- end
355
-
356
- end
357
-
358
- describe 'remove' do
359
-
360
- it 'should remove a parameter' do
361
- configatron.movies = 'Pulp Fiction'
362
- configatron.movies.should == 'Pulp Fiction'
363
- configatron.remove(:movies)
364
- configatron.movies.should be_nil
365
- end
366
-
367
- it 'should remove a nested parameter' do
368
- configatron.the.movies = 'Pulp Fiction'
369
- configatron.the.movies.should == 'Pulp Fiction'
370
- configatron.the.remove(:movies)
371
- configatron.the.movies.should be_nil
372
- end
373
-
374
- it 'should work with a symbol or a string' do
375
- configatron.the.movies = 'Pulp Fiction'
376
- configatron.the.office = 'Michael'
377
- configatron.the.remove(:movies)
378
- configatron.the.movies.should be_nil
379
- configatron.the.remove('office')
380
- configatron.the.office.should be_nil
381
- end
382
-
383
- it 'should remove all sub-parameters' do
384
- configatron.the.movies = 'Pulp Fiction'
385
- configatron.the.office = 'Michael'
386
- configatron.remove(:the)
387
- configatron.the.should be_nil
388
- configatron.the.movies.should be_nil
389
- end
390
-
391
- end
392
-
393
- describe 'set_default' do
394
-
395
- it 'should set a default parameter value' do
396
- configatron.set_default(:movies, 'Pulp Fiction')
397
- configatron.movies.should == 'Pulp Fiction'
398
- end
399
-
400
- it 'should set a default parameter value for a nested parameter' do
401
- configatron.the.set_default(:movies, 'Pulp Fiction')
402
- configatron.the.movies.should == 'Pulp Fiction'
403
- end
404
-
405
- it 'should not set the parameter if it is already set' do
406
- configatron.movies = 'Transformers'
407
- configatron.set_default(:movies, 'Pulp Fiction')
408
- configatron.movies.should == 'Transformers'
409
- end
410
-
411
- it 'should not set the nested parameter if it is already set' do
412
- configatron.the.movies = 'Transformers'
413
- configatron.the.set_default(:movies, 'Pulp Fiction')
414
- configatron.the.movies.should == 'Transformers'
415
- end
416
-
417
- end
418
-
419
- describe 'reset!' do
420
-
421
- it 'should clear out all parameter' do
422
- configatron.one = 1
423
- configatron.letters.a = 'A'
424
- configatron.letters.b = 'B'
425
- configatron.one.should == 1
426
- configatron.letters.a.should == 'A'
427
- configatron.reset!
428
- configatron.one.should be_nil
429
- configatron.letters.a.should be_nil
430
- end
431
-
432
- end
433
-
434
- end