iqeo-conf 0.0.5 → 0.0.6
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/Gemfile.lock +1 -1
- data/README.md +1 -2
- data/lib/iqeo/configuration/version.rb +1 -1
- data/lib/iqeo/configuration.rb +10 -9
- data/pkg/iqeo-conf-0.0.5.gem +0 -0
- data/spec/configuration_spec.rb +314 -123
- metadata +3 -2
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -98,8 +98,7 @@ Need time (have motivation)...
|
|
98
98
|
* Load configurations from a string or file after creation / in DSL block
|
99
99
|
* Option to get hash directly to prevent polluting namespace with delegated hash methods
|
100
100
|
* Blank slate for DSL ? - optional ?
|
101
|
-
*
|
102
|
-
* Issues around deferred interpolation / procs / lambdas etc...
|
101
|
+
* Consider issues around deferred interpolation / procs / lambdas etc...
|
103
102
|
* Load other formats into configuration - YAML, CSV, ...anything Enumerable should be easy enough.
|
104
103
|
|
105
104
|
## License
|
data/lib/iqeo/configuration.rb
CHANGED
@@ -2,15 +2,15 @@
|
|
2
2
|
require_relative "configuration/version"
|
3
3
|
require_relative "configuration/hash_with_indifferent_access"
|
4
4
|
|
5
|
+
# fix: nested configurations broken for DSL !!
|
6
|
+
# todo: clean DSL syntax for creating a configuration - just a block ?
|
5
7
|
# todo: configuration file load path - array of Dir.glob like file specs ?
|
6
8
|
# todo: use an existing configuration for defaults
|
7
|
-
# todo: clean DSL syntax for creating a configuration - just a block ?
|
8
9
|
# todo: load configurations from a string or file after creation / in DSL block
|
9
10
|
# todo: option to get hash directly to prevent polluting namespace with delegated hash methods
|
10
11
|
# todo: blank slate for DSL - optional ?
|
11
|
-
# todo:
|
12
|
-
# todo:
|
13
|
-
# todo: load other formats from string & file - YAML, XML?
|
12
|
+
# todo: consider issues around deferred interpolation / procs / lambdas etc...
|
13
|
+
# todo: load other formats from string & file - YAML, CSV, ...anything Enumerable should be easy enough.
|
14
14
|
|
15
15
|
module Iqeo
|
16
16
|
|
@@ -42,8 +42,8 @@ module Iqeo
|
|
42
42
|
end
|
43
43
|
end
|
44
44
|
|
45
|
-
def method_missing name, *values
|
46
|
-
return @items.send name, *values if @items.respond_to? name
|
45
|
+
def method_missing name, *values, &block
|
46
|
+
return @items.send name, *values if @items.respond_to? name # @items methods are highest priority
|
47
47
|
# this is unreachable since these methods are delegated to @items hash
|
48
48
|
# but keep it around for when we make selective delegation an option
|
49
49
|
#case name
|
@@ -51,9 +51,10 @@ module Iqeo
|
|
51
51
|
#when :[] then return _get values.shift
|
52
52
|
#end
|
53
53
|
name = name.to_s.chomp('=') # todo: write a test case for a non-string object as key being converted by .to_s
|
54
|
-
return
|
55
|
-
return
|
56
|
-
return _set name, values.
|
54
|
+
return _set name, Configuration.new( &block ) if block_given? # block is a nested configuration
|
55
|
+
return _get name if values.empty? # just get item
|
56
|
+
return _set name, values if values.size > 1 # set item to multiple values
|
57
|
+
return _set name, values.first # set item to single value
|
57
58
|
end
|
58
59
|
|
59
60
|
attr_accessor :_parent # todo: should attr_writer be protected ?
|
Binary file
|
data/spec/configuration_spec.rb
CHANGED
@@ -36,7 +36,7 @@ describe Configuration do
|
|
36
36
|
conf_new.should be conf_yielded
|
37
37
|
end
|
38
38
|
|
39
|
-
end
|
39
|
+
end # creation
|
40
40
|
|
41
41
|
context 'settings retrieval' do
|
42
42
|
|
@@ -45,7 +45,7 @@ describe Configuration do
|
|
45
45
|
conf.not_a_setting.should be_nil
|
46
46
|
end
|
47
47
|
|
48
|
-
end
|
48
|
+
end # settings retrieval
|
49
49
|
|
50
50
|
context 'single value setting' do
|
51
51
|
|
@@ -81,7 +81,7 @@ describe Configuration do
|
|
81
81
|
conf.bravo[:c].should == 3
|
82
82
|
end
|
83
83
|
|
84
|
-
end
|
84
|
+
end # single value setting
|
85
85
|
|
86
86
|
context 'multiple value setting' do
|
87
87
|
|
@@ -107,7 +107,7 @@ describe Configuration do
|
|
107
107
|
conf.alpha.should == [ 1, 2, 3, { 'a' => 4, 'b' => 5, 'c' => 6} ] and conf.alpha.should be_a Array
|
108
108
|
end
|
109
109
|
|
110
|
-
end
|
110
|
+
end # multiple value setting
|
111
111
|
|
112
112
|
context 'hash operators [] & []= access' do
|
113
113
|
|
@@ -130,7 +130,7 @@ describe Configuration do
|
|
130
130
|
conf['alpha'].should == 1
|
131
131
|
end
|
132
132
|
|
133
|
-
end
|
133
|
+
end # hash operators [] & []= access
|
134
134
|
|
135
135
|
context 'nested configuration' do
|
136
136
|
|
@@ -208,120 +208,279 @@ describe Configuration do
|
|
208
208
|
conf.alpha.bravo.level.should == 3
|
209
209
|
end
|
210
210
|
|
211
|
-
end
|
212
|
-
|
213
|
-
context '
|
214
|
-
|
215
|
-
|
216
|
-
|
217
|
-
|
218
|
-
conf =
|
219
|
-
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
224
|
-
|
225
|
-
|
226
|
-
|
227
|
-
|
228
|
-
|
229
|
-
|
230
|
-
|
231
|
-
|
232
|
-
|
233
|
-
|
234
|
-
|
235
|
-
|
236
|
-
|
237
|
-
|
238
|
-
|
239
|
-
|
240
|
-
|
241
|
-
|
242
|
-
|
243
|
-
|
244
|
-
end
|
245
|
-
|
246
|
-
|
247
|
-
|
248
|
-
|
249
|
-
|
250
|
-
|
251
|
-
|
252
|
-
|
253
|
-
|
254
|
-
|
255
|
-
|
256
|
-
|
257
|
-
|
258
|
-
|
259
|
-
|
260
|
-
|
261
|
-
|
262
|
-
|
263
|
-
|
264
|
-
|
265
|
-
|
266
|
-
|
267
|
-
|
268
|
-
|
269
|
-
|
270
|
-
|
271
|
-
|
272
|
-
|
273
|
-
|
274
|
-
|
275
|
-
|
276
|
-
|
277
|
-
|
278
|
-
|
279
|
-
|
280
|
-
|
281
|
-
|
282
|
-
|
283
|
-
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
288
|
-
|
289
|
-
|
290
|
-
|
291
|
-
|
292
|
-
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
298
|
-
|
299
|
-
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
304
|
-
|
305
|
-
|
306
|
-
|
307
|
-
|
308
|
-
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
314
|
-
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
211
|
+
end # nested configuration
|
212
|
+
|
213
|
+
context 'mode of usage' do
|
214
|
+
|
215
|
+
context 'explicit' do
|
216
|
+
|
217
|
+
it 'accepts settings without =' do
|
218
|
+
conf = nil
|
219
|
+
expect do
|
220
|
+
conf = Configuration.new
|
221
|
+
conf.alpha :value
|
222
|
+
end.to_not raise_error
|
223
|
+
conf.should_not be_nil
|
224
|
+
conf.alpha.should == :value
|
225
|
+
end
|
226
|
+
|
227
|
+
it 'accepts settings with =' do
|
228
|
+
conf = nil
|
229
|
+
expect do
|
230
|
+
conf = Configuration.new
|
231
|
+
conf.alpha = :value
|
232
|
+
end.to_not raise_error
|
233
|
+
conf.should_not be_nil
|
234
|
+
conf.alpha.should == :value
|
235
|
+
end
|
236
|
+
|
237
|
+
it 'can refer to an existing setting' do
|
238
|
+
conf = nil
|
239
|
+
expect do
|
240
|
+
conf = Configuration.new
|
241
|
+
conf.alpha = :value
|
242
|
+
conf.bravo = conf.alpha
|
243
|
+
conf.charlie conf.bravo
|
244
|
+
end.to_not raise_error
|
245
|
+
conf.should_not be_nil
|
246
|
+
conf.alpha.should == :value
|
247
|
+
conf.bravo.should == :value
|
248
|
+
conf.charlie.should == :value
|
249
|
+
end
|
250
|
+
|
251
|
+
it 'returns value when creating/changing a setting' do
|
252
|
+
conf = nil
|
253
|
+
expect do
|
254
|
+
conf = Configuration.new
|
255
|
+
conf.bravo = conf.alpha = :value
|
256
|
+
end.to_not raise_error
|
257
|
+
conf.should_not be_nil
|
258
|
+
conf.alpha.should == :value
|
259
|
+
conf.bravo.should == :value
|
260
|
+
end
|
261
|
+
|
262
|
+
it 'supports nested configuration via Configuration.new' do
|
263
|
+
conf = nil
|
264
|
+
expect do
|
265
|
+
conf = Configuration.new
|
266
|
+
conf.alpha true
|
267
|
+
conf.bravo Configuration.new
|
268
|
+
conf.bravo.charlie true
|
269
|
+
conf.bravo.delta Configuration.new
|
270
|
+
conf.bravo.delta.echo true
|
271
|
+
end.to_not raise_error
|
272
|
+
conf.should_not be_nil
|
273
|
+
conf.alpha.should be_true
|
274
|
+
conf.bravo.should be_a Configuration
|
275
|
+
conf.bravo.alpha should be_true
|
276
|
+
conf.bravo.charlie should be_true
|
277
|
+
conf.bravo.delta.should be_a Configuration
|
278
|
+
conf.bravo.delta.alpha.should be_true
|
279
|
+
conf.bravo.delta.charlie.should be_true
|
280
|
+
conf.bravo.delta.echo.should be_true
|
281
|
+
end
|
282
|
+
|
283
|
+
end # explicit
|
284
|
+
|
285
|
+
context 'yield DSL' do
|
286
|
+
|
287
|
+
it 'accepts settings without =' do
|
288
|
+
conf = nil
|
289
|
+
expect do
|
290
|
+
conf = Configuration.new do |c|
|
291
|
+
c.alpha :value
|
292
|
+
end
|
293
|
+
end.to_not raise_error
|
294
|
+
conf.should_not be_nil
|
295
|
+
conf.alpha.should == :value
|
296
|
+
end
|
297
|
+
|
298
|
+
it 'accepts settings with =' do
|
299
|
+
conf = nil
|
300
|
+
expect do
|
301
|
+
conf = Configuration.new do |c|
|
302
|
+
c.alpha = :value
|
303
|
+
end
|
304
|
+
end.to_not raise_error
|
305
|
+
conf.should_not be_nil
|
306
|
+
conf.alpha.should == :value
|
307
|
+
end
|
308
|
+
|
309
|
+
it 'can refer to an existing setting' do
|
310
|
+
conf = nil
|
311
|
+
expect do
|
312
|
+
conf = Configuration.new do |c|
|
313
|
+
c.alpha = :value
|
314
|
+
c.bravo = c.alpha
|
315
|
+
c.charlie c.bravo
|
316
|
+
end
|
317
|
+
end.to_not raise_error
|
318
|
+
conf.should_not be_nil
|
319
|
+
conf.alpha.should == :value
|
320
|
+
conf.bravo.should == :value
|
321
|
+
conf.charlie.should == :value
|
322
|
+
end
|
323
|
+
|
324
|
+
it 'returns value when creating/changing a setting' do
|
325
|
+
conf = nil
|
326
|
+
expect do
|
327
|
+
conf = Configuration.new do |c|
|
328
|
+
c.bravo = c.alpha = :value
|
329
|
+
end
|
330
|
+
end.to_not raise_error
|
331
|
+
conf.should_not be_nil
|
332
|
+
conf.alpha.should == :value
|
333
|
+
conf.bravo.should == :value
|
334
|
+
end
|
335
|
+
|
336
|
+
it 'supports nested configuration via do..end' do
|
337
|
+
conf = nil
|
338
|
+
expect do
|
339
|
+
conf = Configuration.new do |c1|
|
340
|
+
c1.alpha true
|
341
|
+
c1.bravo do |c2|
|
342
|
+
c2.charlie true
|
343
|
+
c2.delta do |c3|
|
344
|
+
c3.echo true
|
345
|
+
end
|
346
|
+
end
|
347
|
+
end
|
348
|
+
end.to_not raise_error
|
349
|
+
conf.should_not be_nil
|
350
|
+
conf.alpha.should be_true
|
351
|
+
conf.bravo.should be_a Configuration
|
352
|
+
conf.bravo.alpha should be_true
|
353
|
+
conf.bravo.charlie should be_true
|
354
|
+
conf.bravo.delta.should be_a Configuration
|
355
|
+
conf.bravo.delta.alpha.should be_true
|
356
|
+
conf.bravo.delta.charlie.should be_true
|
357
|
+
conf.bravo.delta.echo.should be_true
|
358
|
+
end
|
359
|
+
|
360
|
+
it 'supports nested configuration via {..}' do
|
361
|
+
conf = nil
|
362
|
+
expect do
|
363
|
+
conf = Configuration.new { |c1| c1.alpha true ; c1.bravo { |c2| c2.charlie true ; c2.delta { |c3| c3.echo true } } }
|
364
|
+
end.to_not raise_error
|
365
|
+
conf.should_not be_nil
|
366
|
+
conf.alpha.should be_true
|
367
|
+
conf.bravo.should be_a Configuration
|
368
|
+
conf.bravo.alpha should be_true
|
369
|
+
conf.bravo.charlie should be_true
|
370
|
+
conf.bravo.delta.should be_a Configuration
|
371
|
+
conf.bravo.delta.alpha.should be_true
|
372
|
+
conf.bravo.delta.charlie.should be_true
|
373
|
+
conf.bravo.delta.echo.should be_true
|
374
|
+
end
|
375
|
+
|
376
|
+
end # yield DSL
|
377
|
+
|
378
|
+
context 'instance_eval DSL' do
|
379
|
+
|
380
|
+
it 'accepts settings without =' do
|
381
|
+
conf = nil
|
382
|
+
expect do
|
383
|
+
conf = Configuration.new do
|
384
|
+
alpha :value
|
385
|
+
end
|
386
|
+
end.to_not raise_error
|
387
|
+
conf.should_not be_nil
|
388
|
+
conf.alpha.should == :value
|
389
|
+
end
|
390
|
+
|
391
|
+
it 'sets local variables with =' do
|
392
|
+
conf = alpha = nil
|
393
|
+
expect do
|
394
|
+
alpha = nil
|
395
|
+
conf = Configuration.new do
|
396
|
+
alpha = :value
|
397
|
+
bravo alpha
|
398
|
+
end
|
399
|
+
end.to_not raise_error
|
400
|
+
conf.should_not be_nil
|
401
|
+
conf.alpha.should be_nil
|
402
|
+
conf.bravo.should == :value
|
403
|
+
alpha.should == :value # local alpha set by matching variables
|
404
|
+
end
|
405
|
+
|
406
|
+
it 'can refer to an existing setting' do
|
407
|
+
conf = nil
|
408
|
+
expect do
|
409
|
+
conf = Configuration.new do
|
410
|
+
alpha :value
|
411
|
+
bravo alpha
|
412
|
+
charlie bravo
|
413
|
+
end
|
414
|
+
end.to_not raise_error
|
415
|
+
conf.should_not be_nil
|
416
|
+
conf.alpha.should == :value
|
417
|
+
conf.bravo.should == :value
|
418
|
+
conf.charlie.should == :value
|
419
|
+
end
|
420
|
+
|
421
|
+
it 'returns value when creating/changing a setting' do
|
422
|
+
conf = nil
|
423
|
+
expect do
|
424
|
+
conf = Configuration.new do
|
425
|
+
bravo alpha :value
|
426
|
+
end
|
427
|
+
end.to_not raise_error
|
428
|
+
conf.should_not be_nil
|
429
|
+
conf.alpha.should == :value
|
430
|
+
conf.bravo.should == :value
|
431
|
+
end
|
432
|
+
|
433
|
+
it 'supports nested configuration via do..end' do
|
434
|
+
conf = nil
|
435
|
+
expect do
|
436
|
+
conf = Configuration.new do
|
437
|
+
alpha true
|
438
|
+
bravo do
|
439
|
+
charlie true
|
440
|
+
delta do
|
441
|
+
echo true
|
442
|
+
end
|
443
|
+
end
|
444
|
+
end
|
445
|
+
end.to_not raise_error
|
446
|
+
conf.should_not be_nil
|
447
|
+
conf.alpha.should be_true
|
448
|
+
conf.bravo.should be_a Configuration
|
449
|
+
conf.bravo.alpha should be_true
|
450
|
+
conf.bravo.charlie should be_true
|
451
|
+
conf.bravo.delta.should be_a Configuration
|
452
|
+
conf.bravo.delta.alpha.should be_true
|
453
|
+
conf.bravo.delta.charlie.should be_true
|
454
|
+
conf.bravo.delta.echo.should be_true
|
455
|
+
end
|
456
|
+
|
457
|
+
it 'supports nested configuration via {..}' do
|
458
|
+
conf = nil
|
459
|
+
expect do
|
460
|
+
conf = Configuration.new { |c1| c1.alpha true ; c1.bravo { |c2| c2.charlie true ; c2.delta { |c3| c3.echo true } } }
|
461
|
+
end.to_not raise_error
|
462
|
+
conf.should_not be_nil
|
463
|
+
conf.alpha.should be_true
|
464
|
+
conf.bravo.should be_a Configuration
|
465
|
+
conf.bravo.alpha should be_true
|
466
|
+
conf.bravo.charlie should be_true
|
467
|
+
conf.bravo.delta.should be_a Configuration
|
468
|
+
conf.bravo.delta.alpha.should be_true
|
469
|
+
conf.bravo.delta.charlie.should be_true
|
470
|
+
conf.bravo.delta.echo.should be_true
|
471
|
+
end
|
472
|
+
|
473
|
+
end # instance_eval DSL
|
474
|
+
|
475
|
+
end # mode of usage
|
320
476
|
|
321
477
|
context 'loads' do
|
322
478
|
|
323
|
-
it 'simple
|
324
|
-
string = "alpha 1
|
479
|
+
it 'simple instance_eval DSL from string' do
|
480
|
+
string = "alpha 1
|
481
|
+
bravo 'two'
|
482
|
+
charlie 3.0
|
483
|
+
delta :four"
|
325
484
|
conf = nil
|
326
485
|
expect do
|
327
486
|
conf = Configuration.read string
|
@@ -333,8 +492,11 @@ describe Configuration do
|
|
333
492
|
conf.delta.should == :four and conf.delta.should be_a Symbol
|
334
493
|
end
|
335
494
|
|
336
|
-
it 'simple
|
337
|
-
io = StringIO.new
|
495
|
+
it 'simple instance_eval DSL from file (by StringIO fake)' do
|
496
|
+
io = StringIO.new "alpha 1
|
497
|
+
bravo 'two'
|
498
|
+
charlie 3.0
|
499
|
+
delta :four"
|
338
500
|
conf = nil
|
339
501
|
expect do
|
340
502
|
conf = Configuration.file io
|
@@ -346,10 +508,13 @@ describe Configuration do
|
|
346
508
|
conf.delta.should == :four and conf.delta.should be_a Symbol
|
347
509
|
end
|
348
510
|
|
349
|
-
it 'simple
|
511
|
+
it 'simple instance_eval DSL from file (by mock and expected methods)' do
|
350
512
|
file = mock
|
351
513
|
file.should_receive( :respond_to? ).with( :read ).and_return true
|
352
|
-
file.should_receive( :read ).and_return
|
514
|
+
file.should_receive( :read ).and_return "alpha 1
|
515
|
+
bravo 'two'
|
516
|
+
charlie 3.0
|
517
|
+
delta :four"
|
353
518
|
conf = nil
|
354
519
|
expect do
|
355
520
|
conf = Configuration.file file
|
@@ -361,8 +526,11 @@ describe Configuration do
|
|
361
526
|
conf.delta.should == :four and conf.delta.should be_a Symbol
|
362
527
|
end
|
363
528
|
|
364
|
-
it 'simple
|
365
|
-
File.should_receive( :read ).with( "filename" ).and_return "alpha 1
|
529
|
+
it 'simple instance_eval DSL from filename (by expected methods)' do
|
530
|
+
File.should_receive( :read ).with( "filename" ).and_return "alpha 1
|
531
|
+
bravo 'two'
|
532
|
+
charlie 3.0
|
533
|
+
delta :four"
|
366
534
|
conf = nil
|
367
535
|
expect do
|
368
536
|
conf = Configuration.file "filename"
|
@@ -374,7 +542,30 @@ describe Configuration do
|
|
374
542
|
conf.delta.should == :four and conf.delta.should be_a Symbol
|
375
543
|
end
|
376
544
|
|
377
|
-
|
545
|
+
it 'complex instance_eval DSL from string' do
|
546
|
+
string = "alpha true
|
547
|
+
bravo do
|
548
|
+
charlie true
|
549
|
+
delta do
|
550
|
+
echo true
|
551
|
+
end
|
552
|
+
end"
|
553
|
+
conf = nil
|
554
|
+
expect do
|
555
|
+
conf = Configuration.read string
|
556
|
+
end.to_not raise_error
|
557
|
+
conf.should_not be_nil
|
558
|
+
conf.alpha.should be_true
|
559
|
+
conf.bravo.should be_a Configuration
|
560
|
+
conf.bravo.alpha should be_true
|
561
|
+
conf.bravo.charlie should be_true
|
562
|
+
conf.bravo.delta.should be_a Configuration
|
563
|
+
conf.bravo.delta.alpha.should be_true
|
564
|
+
conf.bravo.delta.charlie.should be_true
|
565
|
+
conf.bravo.delta.echo.should be_true
|
566
|
+
end
|
567
|
+
|
568
|
+
end # loads
|
378
569
|
|
379
570
|
it 'delegates hash methods to internal hash' do
|
380
571
|
conf = nil
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iqeo-conf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.6
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,7 +9,7 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-05-01 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -67,6 +67,7 @@ files:
|
|
67
67
|
- pkg/iqeo-conf-0.0.2.gem
|
68
68
|
- pkg/iqeo-conf-0.0.3.gem
|
69
69
|
- pkg/iqeo-conf-0.0.4.gem
|
70
|
+
- pkg/iqeo-conf-0.0.5.gem
|
70
71
|
- spec/configuration_spec.rb
|
71
72
|
- spec/spec_helper.rb
|
72
73
|
homepage: http://iqeo.github.com/iqeo-conf
|