iqeo-conf 0.0.9 → 0.0.10
Sign up to get free protection for your applications and to get access to all the features.
- data/.gitignore +1 -0
- data/Gemfile.lock +3 -1
- data/README.md +3 -3
- data/iqeo-conf.gemspec +2 -0
- data/lib/iqeo/configuration/version.rb +1 -1
- data/lib/iqeo/configuration.rb +13 -6
- data/pkg/iqeo-conf-0.0.9.gem +0 -0
- data/spec/configuration_spec.rb +479 -299
- metadata +19 -3
- data/.bundle/config +0 -2
data/.gitignore
CHANGED
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -87,6 +87,8 @@ Need docs...
|
|
87
87
|
* Load configurations from a string or file at creation
|
88
88
|
* Iterate over items hash - by delegation to hash
|
89
89
|
* Indifferent hash access - using ActiveSupport/HashWithIndifferentAccess
|
90
|
+
* Clean DSL syntax for creating a nested configuration - just a block ?
|
91
|
+
* Load configurations from a string or file after creation / in DSL block
|
90
92
|
|
91
93
|
## Todo
|
92
94
|
|
@@ -94,10 +96,8 @@ Need time (have motivation)...
|
|
94
96
|
|
95
97
|
* Configuration file load path
|
96
98
|
* Use an existing configuration for defaults
|
97
|
-
* Clean DSL syntax for creating a nested configuration - just a block ?
|
98
|
-
* Load configurations from a string or file after creation / in DSL block
|
99
|
-
* Option to get hash directly to prevent polluting namespace with delegated hash methods
|
100
99
|
* Blank slate for DSL ? - optional ?
|
100
|
+
* Option to get hash directly to prevent polluting namespace with delegated hash methods
|
101
101
|
* Consider issues around deferred interpolation / procs / lambdas etc...
|
102
102
|
* Load other formats into configuration - YAML, CSV, ...anything Enumerable should be easy enough.
|
103
103
|
|
data/iqeo-conf.gemspec
CHANGED
data/lib/iqeo/configuration.rb
CHANGED
@@ -4,9 +4,8 @@ require_relative "configuration/hash_with_indifferent_access"
|
|
4
4
|
|
5
5
|
# todo: configuration file load path - array of Dir.glob like file specs ?
|
6
6
|
# todo: use an existing configuration for defaults
|
7
|
-
# todo: load configurations from a string or file after creation / in DSL block
|
8
|
-
# todo: option to get hash directly to prevent polluting namespace with delegated hash methods
|
9
7
|
# todo: blank slate for DSL - optional ?
|
8
|
+
# todo: option to get hash directly to prevent polluting namespace with delegated hash methods
|
10
9
|
# todo: consider issues around deferred interpolation / procs / lambdas etc...
|
11
10
|
# todo: load other formats from string & file - YAML, CSV, ...anything Enumerable should be easy enough.
|
12
11
|
|
@@ -57,7 +56,7 @@ module Iqeo
|
|
57
56
|
def method_missing name, *values, &block
|
58
57
|
return @items.send( name, *values, &block ) if @items.respond_to? name # @items methods are highest priority
|
59
58
|
|
60
|
-
name = name.to_s.chomp('=')
|
59
|
+
name = name.to_s.chomp('=')
|
61
60
|
|
62
61
|
if block_given? # block is a nested configuration
|
63
62
|
if block.arity == 1 # yield DSL needs deferred block to set parent without binding
|
@@ -72,10 +71,10 @@ module Iqeo
|
|
72
71
|
return _set name, values.first # set item to single value
|
73
72
|
end
|
74
73
|
|
75
|
-
attr_accessor :_parent
|
74
|
+
attr_accessor :_parent
|
76
75
|
|
77
76
|
def _set key, value
|
78
|
-
#
|
77
|
+
# fix: extend parenting for enumerable with configurations at arbitrary depth
|
79
78
|
case
|
80
79
|
when value.kind_of?( Configuration ) then value._parent = self
|
81
80
|
when value.kind_of?( Enumerable ) then value.each { |v| v._parent = self if v.kind_of? Configuration }
|
@@ -87,10 +86,18 @@ module Iqeo
|
|
87
86
|
def _get key
|
88
87
|
return @items[key] unless @items[key].nil?
|
89
88
|
return @items[key] if _parent.nil?
|
90
|
-
|
89
|
+
_parent._get key
|
91
90
|
end
|
92
91
|
alias [] _get
|
93
92
|
|
93
|
+
def _read string
|
94
|
+
instance_eval string
|
95
|
+
end
|
96
|
+
|
97
|
+
def _file file
|
98
|
+
_read file.respond_to?(:read) ? file.read : File.read(file)
|
99
|
+
end
|
100
|
+
|
94
101
|
end
|
95
102
|
|
96
103
|
end
|
Binary file
|
data/spec/configuration_spec.rb
CHANGED
@@ -10,32 +10,125 @@ describe Configuration do
|
|
10
10
|
Configuration.version.should == Configuration::VERSION
|
11
11
|
end
|
12
12
|
|
13
|
-
context 'creation' do
|
13
|
+
context 'at creation' do
|
14
14
|
|
15
15
|
it 'does not require a block' do
|
16
16
|
Configuration.new.should be_a Configuration
|
17
17
|
end
|
18
18
|
|
19
|
-
it '
|
19
|
+
it 'accept a block with arity 0' do
|
20
20
|
Configuration.new { }.should be_a Configuration
|
21
21
|
end
|
22
22
|
|
23
|
-
it 'instance_eval
|
23
|
+
it 'instance_eval a block with arity 0' do
|
24
24
|
conf_eval = nil
|
25
25
|
conf_new = Configuration.new { conf_eval = self }
|
26
26
|
conf_new.should be conf_eval
|
27
27
|
end
|
28
28
|
|
29
|
-
it '
|
29
|
+
it 'accept a block with arity 1' do
|
30
30
|
Configuration.new { |arg| }.should be_a Configuration
|
31
31
|
end
|
32
32
|
|
33
|
-
it '
|
33
|
+
it 'yield self to block with arity 1' do
|
34
34
|
conf_yielded = nil
|
35
35
|
conf_new = Configuration.new { |conf| conf_yielded = conf }
|
36
36
|
conf_new.should be conf_yielded
|
37
37
|
end
|
38
38
|
|
39
|
+
context 'can load' do
|
40
|
+
|
41
|
+
it 'simple instance_eval DSL from string' do
|
42
|
+
string = "alpha 1
|
43
|
+
bravo 'two'
|
44
|
+
charlie 3.0
|
45
|
+
delta :four"
|
46
|
+
conf = nil
|
47
|
+
expect do
|
48
|
+
conf = Configuration.read string
|
49
|
+
end.to_not raise_error
|
50
|
+
conf.should_not be_nil
|
51
|
+
conf.alpha.should == 1 and conf.alpha.should be_a Fixnum
|
52
|
+
conf.bravo.should == "two" and conf.bravo.should be_a String
|
53
|
+
conf.charlie.should == 3.0 and conf.charlie.should be_a Float
|
54
|
+
conf.delta.should == :four and conf.delta.should be_a Symbol
|
55
|
+
end
|
56
|
+
|
57
|
+
it 'simple instance_eval DSL from file (StringIO)' do
|
58
|
+
io = StringIO.new "alpha 1
|
59
|
+
bravo 'two'
|
60
|
+
charlie 3.0
|
61
|
+
delta :four"
|
62
|
+
conf = nil
|
63
|
+
expect do
|
64
|
+
conf = Configuration.file io
|
65
|
+
end.to_not raise_error
|
66
|
+
conf.should_not be_nil
|
67
|
+
conf.alpha.should == 1 and conf.alpha.should be_a Fixnum
|
68
|
+
conf.bravo.should == "two" and conf.bravo.should be_a String
|
69
|
+
conf.charlie.should == 3.0 and conf.charlie.should be_a Float
|
70
|
+
conf.delta.should == :four and conf.delta.should be_a Symbol
|
71
|
+
end
|
72
|
+
|
73
|
+
it 'simple instance_eval DSL from file (mock & expected methods)' do
|
74
|
+
file = mock
|
75
|
+
file.should_receive( :respond_to? ).with( :read ).and_return true
|
76
|
+
file.should_receive( :read ).and_return "alpha 1
|
77
|
+
bravo 'two'
|
78
|
+
charlie 3.0
|
79
|
+
delta :four"
|
80
|
+
conf = nil
|
81
|
+
expect do
|
82
|
+
conf = Configuration.file file
|
83
|
+
end.to_not raise_error
|
84
|
+
conf.should_not be_nil
|
85
|
+
conf.alpha.should == 1 and conf.alpha.should be_a Fixnum
|
86
|
+
conf.bravo.should == "two" and conf.bravo.should be_a String
|
87
|
+
conf.charlie.should == 3.0 and conf.charlie.should be_a Float
|
88
|
+
conf.delta.should == :four and conf.delta.should be_a Symbol
|
89
|
+
end
|
90
|
+
|
91
|
+
it 'simple instance_eval DSL from filename (expected methods)' do
|
92
|
+
File.should_receive( :read ).with( "filename" ).and_return "alpha 1
|
93
|
+
bravo 'two'
|
94
|
+
charlie 3.0
|
95
|
+
delta :four"
|
96
|
+
conf = nil
|
97
|
+
expect do
|
98
|
+
conf = Configuration.file "filename"
|
99
|
+
end.to_not raise_error
|
100
|
+
conf.should_not be_nil
|
101
|
+
conf.alpha.should == 1 and conf.alpha.should be_a Fixnum
|
102
|
+
conf.bravo.should == "two" and conf.bravo.should be_a String
|
103
|
+
conf.charlie.should == 3.0 and conf.charlie.should be_a Float
|
104
|
+
conf.delta.should == :four and conf.delta.should be_a Symbol
|
105
|
+
end
|
106
|
+
|
107
|
+
it 'complex instance_eval DSL from string' do
|
108
|
+
string = "alpha true
|
109
|
+
bravo do
|
110
|
+
charlie true
|
111
|
+
delta do
|
112
|
+
echo true
|
113
|
+
end
|
114
|
+
end"
|
115
|
+
conf = nil
|
116
|
+
expect do
|
117
|
+
conf = Configuration.read string
|
118
|
+
end.to_not raise_error
|
119
|
+
conf.should_not be_nil
|
120
|
+
conf.alpha.should be_true
|
121
|
+
conf.bravo.should be_a Configuration
|
122
|
+
conf.bravo.alpha should be_true
|
123
|
+
conf.bravo.charlie should be_true
|
124
|
+
conf.bravo.delta.should be_a Configuration
|
125
|
+
conf.bravo.delta.alpha.should be_true
|
126
|
+
conf.bravo.delta.charlie.should be_true
|
127
|
+
conf.bravo.delta.echo.should be_true
|
128
|
+
end
|
129
|
+
|
130
|
+
end # loads
|
131
|
+
|
39
132
|
end # creation
|
40
133
|
|
41
134
|
context 'settings retrieval' do
|
@@ -45,6 +138,24 @@ describe Configuration do
|
|
45
138
|
conf.not_a_setting.should be_nil
|
46
139
|
end
|
47
140
|
|
141
|
+
it 'delegates hash methods to internal hash' do
|
142
|
+
conf = nil
|
143
|
+
expect do
|
144
|
+
conf = Configuration.new
|
145
|
+
conf.alpha 1
|
146
|
+
conf.bravo 2
|
147
|
+
conf.charlie 3
|
148
|
+
conf.delta 4
|
149
|
+
end.to_not raise_error
|
150
|
+
conf.should_not be_nil
|
151
|
+
sum = 0
|
152
|
+
expect do
|
153
|
+
conf.each { |k,v| sum += v }
|
154
|
+
end.to_not raise_error
|
155
|
+
sum.should == 10
|
156
|
+
conf.size.should == 4
|
157
|
+
end
|
158
|
+
|
48
159
|
end # settings retrieval
|
49
160
|
|
50
161
|
context 'single value setting' do
|
@@ -333,75 +444,163 @@ describe Configuration do
|
|
333
444
|
conf.bravo.should == :value
|
334
445
|
end
|
335
446
|
|
336
|
-
|
337
|
-
|
338
|
-
|
339
|
-
conf =
|
340
|
-
|
341
|
-
|
342
|
-
|
343
|
-
|
344
|
-
|
447
|
+
context 'nested configuration' do
|
448
|
+
|
449
|
+
it 'supported via do..end' do
|
450
|
+
conf = nil
|
451
|
+
expect do
|
452
|
+
conf = Configuration.new do |c1|
|
453
|
+
c1.alpha true
|
454
|
+
c1.bravo do |c2|
|
455
|
+
c2.charlie true
|
456
|
+
c2.delta do |c3|
|
457
|
+
c3.echo true
|
458
|
+
end
|
345
459
|
end
|
346
460
|
end
|
347
|
-
end
|
348
|
-
|
349
|
-
|
350
|
-
|
351
|
-
|
352
|
-
|
353
|
-
|
354
|
-
|
355
|
-
|
356
|
-
|
357
|
-
|
358
|
-
|
359
|
-
|
360
|
-
|
361
|
-
|
362
|
-
|
363
|
-
|
364
|
-
|
365
|
-
|
366
|
-
|
367
|
-
|
368
|
-
|
369
|
-
|
370
|
-
|
371
|
-
|
372
|
-
|
373
|
-
|
374
|
-
|
375
|
-
|
376
|
-
|
377
|
-
|
378
|
-
|
379
|
-
|
380
|
-
|
381
|
-
|
382
|
-
|
383
|
-
|
384
|
-
|
385
|
-
|
386
|
-
|
387
|
-
|
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
|
+
it 'supported via {..}' do
|
474
|
+
conf = nil
|
475
|
+
expect do
|
476
|
+
conf = Configuration.new { |c1| c1.alpha true ; c1.bravo { |c2| c2.charlie true ; c2.delta { |c3| c3.echo true } } }
|
477
|
+
end.to_not raise_error
|
478
|
+
conf.should_not be_nil
|
479
|
+
conf.alpha.should be_true
|
480
|
+
conf.bravo.should be_a Configuration
|
481
|
+
conf.bravo.alpha should be_true
|
482
|
+
conf.bravo.charlie should be_true
|
483
|
+
conf.bravo.delta.should be_a Configuration
|
484
|
+
conf.bravo.delta.alpha.should be_true
|
485
|
+
conf.bravo.delta.charlie.should be_true
|
486
|
+
conf.bravo.delta.echo.should be_true
|
487
|
+
end
|
488
|
+
|
489
|
+
it 'can refer to an inherited setting' do
|
490
|
+
conf = nil
|
491
|
+
expect do
|
492
|
+
conf = Configuration.new do |c1|
|
493
|
+
c1.alpha true
|
494
|
+
c1.hotel c1.alpha
|
495
|
+
c1.bravo do |c2|
|
496
|
+
c2.charlie true
|
497
|
+
c2.foxtrot c2.alpha
|
498
|
+
c2.delta do |c3|
|
499
|
+
c3.echo true
|
500
|
+
c3.golf c3.alpha
|
501
|
+
end
|
388
502
|
end
|
389
503
|
end
|
390
|
-
end
|
391
|
-
|
392
|
-
|
393
|
-
|
394
|
-
|
395
|
-
|
396
|
-
|
397
|
-
|
398
|
-
|
399
|
-
|
400
|
-
|
401
|
-
|
402
|
-
|
403
|
-
|
404
|
-
|
504
|
+
end.to_not raise_error
|
505
|
+
conf.should_not be_nil
|
506
|
+
conf.alpha.should be_true
|
507
|
+
conf.bravo.should be_a Configuration
|
508
|
+
conf.bravo.alpha should be_true
|
509
|
+
conf.bravo.charlie should be_true
|
510
|
+
conf.bravo.delta.should be_a Configuration
|
511
|
+
conf.bravo.delta.alpha.should be_true
|
512
|
+
conf.bravo.delta.charlie.should be_true
|
513
|
+
conf.bravo.delta.echo.should be_true
|
514
|
+
conf.bravo.delta.golf.should be_true
|
515
|
+
conf.bravo.foxtrot.should be_true
|
516
|
+
conf.hotel.should be_true
|
517
|
+
end
|
518
|
+
|
519
|
+
end # nested configuration
|
520
|
+
|
521
|
+
context 'can load' do
|
522
|
+
|
523
|
+
it 'settings into the current configuration from a string' do
|
524
|
+
conf = nil
|
525
|
+
expect do
|
526
|
+
conf = Configuration.new do |c|
|
527
|
+
c.alpha true
|
528
|
+
c._read "bravo true\ncharlie true"
|
529
|
+
end
|
530
|
+
end.to_not raise_error
|
531
|
+
conf.should_not be_nil
|
532
|
+
conf.alpha.should be_true
|
533
|
+
conf.bravo.should be_true
|
534
|
+
conf.charlie.should be_true
|
535
|
+
end
|
536
|
+
|
537
|
+
it 'settings into the current configuration from a file (StringIO)' do
|
538
|
+
io = StringIO.new "bravo true
|
539
|
+
charlie true"
|
540
|
+
conf = nil
|
541
|
+
expect do
|
542
|
+
conf = Configuration.new do |c|
|
543
|
+
c.alpha true
|
544
|
+
c._file io
|
545
|
+
end
|
546
|
+
end.to_not raise_error
|
547
|
+
conf.should_not be_nil
|
548
|
+
conf.alpha.should be_true
|
549
|
+
conf.bravo.should be_true
|
550
|
+
conf.charlie.should be_true
|
551
|
+
end
|
552
|
+
|
553
|
+
it 'settings into a nested configuration from a string' do
|
554
|
+
conf = nil
|
555
|
+
expect do
|
556
|
+
conf = Configuration.new do |c|
|
557
|
+
c.alpha true
|
558
|
+
c.bravo do |x|
|
559
|
+
x._read "charlie true\ndelta true"
|
560
|
+
end
|
561
|
+
c.echo { |x| x._read "foxtrot true\nhotel true" }
|
562
|
+
end
|
563
|
+
end.to_not raise_error
|
564
|
+
conf.should_not be_nil
|
565
|
+
conf.alpha.should be_true
|
566
|
+
conf.bravo.should be_a Configuration
|
567
|
+
conf.bravo.charlie.should be_true
|
568
|
+
conf.bravo.delta.should be_true
|
569
|
+
conf.bravo.alpha.should be_true
|
570
|
+
conf.echo.should be_a Configuration
|
571
|
+
conf.echo.foxtrot.should be_true
|
572
|
+
conf.echo.hotel.should be_true
|
573
|
+
conf.echo.alpha.should be_true
|
574
|
+
end
|
575
|
+
|
576
|
+
it 'settings into a nested configuration from a file (StringIO)' do
|
577
|
+
io1 = StringIO.new "charlie true
|
578
|
+
delta true"
|
579
|
+
io2 = StringIO.new "foxtrot true
|
580
|
+
hotel true"
|
581
|
+
conf = nil
|
582
|
+
expect do
|
583
|
+
conf = Configuration.new do |c|
|
584
|
+
c.alpha true
|
585
|
+
c.bravo do |x|
|
586
|
+
x._file io1
|
587
|
+
end
|
588
|
+
c.echo { |x| x._file io2 }
|
589
|
+
end
|
590
|
+
end.to_not raise_error
|
591
|
+
conf.should_not be_nil
|
592
|
+
conf.alpha.should be_true
|
593
|
+
conf.bravo.should be_a Configuration
|
594
|
+
conf.bravo.charlie.should be_true
|
595
|
+
conf.bravo.delta.should be_true
|
596
|
+
conf.bravo.alpha.should be_true
|
597
|
+
conf.echo.should be_a Configuration
|
598
|
+
conf.echo.foxtrot.should be_true
|
599
|
+
conf.echo.hotel.should be_true
|
600
|
+
conf.echo.alpha.should be_true
|
601
|
+
end
|
602
|
+
|
603
|
+
end # can load
|
405
604
|
|
406
605
|
end # yield DSL
|
407
606
|
|
@@ -460,243 +659,224 @@ describe Configuration do
|
|
460
659
|
conf.bravo.should == :value
|
461
660
|
end
|
462
661
|
|
463
|
-
|
464
|
-
|
465
|
-
|
466
|
-
conf =
|
467
|
-
|
468
|
-
|
469
|
-
|
470
|
-
|
471
|
-
|
662
|
+
context 'nested configuration' do
|
663
|
+
|
664
|
+
it 'supported via do..end' do
|
665
|
+
conf = nil
|
666
|
+
expect do
|
667
|
+
conf = Configuration.new do
|
668
|
+
alpha true
|
669
|
+
bravo do
|
670
|
+
charlie true
|
671
|
+
delta do
|
672
|
+
echo true
|
673
|
+
end
|
472
674
|
end
|
473
675
|
end
|
474
|
-
end
|
475
|
-
|
476
|
-
|
477
|
-
|
478
|
-
|
479
|
-
|
480
|
-
|
481
|
-
|
482
|
-
|
483
|
-
|
484
|
-
|
485
|
-
|
486
|
-
|
487
|
-
|
488
|
-
|
489
|
-
|
490
|
-
|
491
|
-
|
492
|
-
|
493
|
-
|
494
|
-
|
495
|
-
|
496
|
-
|
497
|
-
|
498
|
-
|
499
|
-
|
500
|
-
|
501
|
-
|
502
|
-
|
503
|
-
|
504
|
-
|
505
|
-
|
506
|
-
|
507
|
-
|
508
|
-
|
509
|
-
|
510
|
-
|
511
|
-
|
512
|
-
|
513
|
-
|
514
|
-
|
676
|
+
end.to_not raise_error
|
677
|
+
conf.should_not be_nil
|
678
|
+
conf.alpha.should be_true
|
679
|
+
conf.bravo.should be_a Configuration
|
680
|
+
conf.bravo.alpha should be_true
|
681
|
+
conf.bravo.charlie should be_true
|
682
|
+
conf.bravo.delta.should be_a Configuration
|
683
|
+
conf.bravo.delta.alpha.should be_true
|
684
|
+
conf.bravo.delta.charlie.should be_true
|
685
|
+
conf.bravo.delta.echo.should be_true
|
686
|
+
end
|
687
|
+
|
688
|
+
it 'supported via {..}' do
|
689
|
+
conf = nil
|
690
|
+
expect do
|
691
|
+
conf = Configuration.new { |c1| c1.alpha true ; c1.bravo { |c2| c2.charlie true ; c2.delta { |c3| c3.echo true } } }
|
692
|
+
end.to_not raise_error
|
693
|
+
conf.should_not be_nil
|
694
|
+
conf.alpha.should be_true
|
695
|
+
conf.bravo.should be_a Configuration
|
696
|
+
conf.bravo.alpha should be_true
|
697
|
+
conf.bravo.charlie should be_true
|
698
|
+
conf.bravo.delta.should be_a Configuration
|
699
|
+
conf.bravo.delta.alpha.should be_true
|
700
|
+
conf.bravo.delta.charlie.should be_true
|
701
|
+
conf.bravo.delta.echo.should be_true
|
702
|
+
end
|
703
|
+
|
704
|
+
it 'can refer to an inherited setting' do
|
705
|
+
conf = nil
|
706
|
+
expect do
|
707
|
+
conf = Configuration.new do
|
708
|
+
alpha true
|
709
|
+
hotel alpha
|
710
|
+
bravo do
|
711
|
+
charlie true
|
712
|
+
foxtrot alpha
|
713
|
+
delta do
|
714
|
+
echo true
|
715
|
+
golf alpha
|
716
|
+
end
|
515
717
|
end
|
516
718
|
end
|
517
|
-
end
|
518
|
-
|
519
|
-
|
520
|
-
|
521
|
-
|
522
|
-
|
523
|
-
|
524
|
-
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
|
532
|
-
|
533
|
-
|
534
|
-
|
535
|
-
|
536
|
-
|
537
|
-
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
545
|
-
conf.alpha.should be_true
|
546
|
-
conf.bravo.should be_true
|
547
|
-
conf.charlie.should be_true
|
548
|
-
end
|
549
|
-
|
550
|
-
it 'dynamic setting name can be a setting' do
|
551
|
-
conf = nil
|
552
|
-
expect do
|
553
|
-
conf = Configuration.new do
|
554
|
-
alpha true
|
555
|
-
setting1 'bravo'
|
556
|
-
self[setting1] = true
|
557
|
-
setting2 'charlie'
|
558
|
-
self[setting2] = true
|
559
|
-
end
|
560
|
-
end.to_not raise_error
|
561
|
-
conf.should_not be_nil
|
562
|
-
conf.alpha.should be_true
|
563
|
-
conf.bravo.should be_true
|
564
|
-
conf.charlie.should be_true
|
565
|
-
conf.setting1.should == 'bravo'
|
566
|
-
conf.setting2.should == 'charlie'
|
567
|
-
end
|
568
|
-
|
569
|
-
it 'dynamic setting can reference a nested configuration' do
|
570
|
-
conf = nil
|
571
|
-
expect do
|
572
|
-
conf = Configuration.new do
|
573
|
-
alpha true
|
574
|
-
local = :bravo
|
575
|
-
self[local] = Configuration.new do
|
576
|
-
charlie true
|
719
|
+
end.to_not raise_error
|
720
|
+
conf.should_not be_nil
|
721
|
+
conf.alpha.should be_true
|
722
|
+
conf.bravo.should be_a Configuration
|
723
|
+
conf.bravo.alpha should be_true
|
724
|
+
conf.bravo.charlie should be_true
|
725
|
+
conf.bravo.delta.should be_a Configuration
|
726
|
+
conf.bravo.delta.alpha.should be_true
|
727
|
+
conf.bravo.delta.charlie.should be_true
|
728
|
+
conf.bravo.delta.echo.should be_true
|
729
|
+
conf.bravo.delta.golf.should be_true
|
730
|
+
conf.bravo.foxtrot.should be_true
|
731
|
+
conf.hotel.should be_true
|
732
|
+
end
|
733
|
+
|
734
|
+
end # nested configuration
|
735
|
+
|
736
|
+
context 'dynamic setting' do
|
737
|
+
|
738
|
+
it 'name can be a local' do
|
739
|
+
conf = nil
|
740
|
+
expect do
|
741
|
+
conf = Configuration.new do
|
742
|
+
alpha true
|
743
|
+
local1 = 'bravo'
|
744
|
+
self[local1] = true
|
745
|
+
local2 = 'charlie'
|
746
|
+
self[local2] = true
|
577
747
|
end
|
578
|
-
end
|
579
|
-
|
580
|
-
|
581
|
-
|
582
|
-
|
583
|
-
|
584
|
-
|
585
|
-
|
748
|
+
end.to_not raise_error
|
749
|
+
conf.should_not be_nil
|
750
|
+
conf.alpha.should be_true
|
751
|
+
conf.bravo.should be_true
|
752
|
+
conf.charlie.should be_true
|
753
|
+
end
|
754
|
+
|
755
|
+
it 'name can be a setting' do
|
756
|
+
conf = nil
|
757
|
+
expect do
|
758
|
+
conf = Configuration.new do
|
759
|
+
alpha true
|
760
|
+
setting1 'bravo'
|
761
|
+
self[setting1] = true
|
762
|
+
setting2 'charlie'
|
763
|
+
self[setting2] = true
|
764
|
+
end
|
765
|
+
end.to_not raise_error
|
766
|
+
conf.should_not be_nil
|
767
|
+
conf.alpha.should be_true
|
768
|
+
conf.bravo.should be_true
|
769
|
+
conf.charlie.should be_true
|
770
|
+
conf.setting1.should == 'bravo'
|
771
|
+
conf.setting2.should == 'charlie'
|
772
|
+
end
|
773
|
+
|
774
|
+
it 'can reference a nested configuration' do
|
775
|
+
conf = nil
|
776
|
+
expect do
|
777
|
+
conf = Configuration.new do
|
778
|
+
alpha true
|
779
|
+
local = :bravo
|
780
|
+
self[local] = Configuration.new do
|
781
|
+
charlie true
|
782
|
+
end
|
783
|
+
end
|
784
|
+
end.to_not raise_error
|
785
|
+
conf.should_not be_nil
|
786
|
+
conf.alpha.should be_true
|
787
|
+
conf.bravo.should be_a Configuration
|
788
|
+
conf.bravo.alpha should be_true
|
789
|
+
conf.bravo.charlie should be_true
|
790
|
+
end
|
791
|
+
|
792
|
+
end # dynamic setting
|
793
|
+
|
794
|
+
context 'can load' do
|
795
|
+
|
796
|
+
it 'settings into the current configuration from a string' do
|
797
|
+
conf = nil
|
798
|
+
expect do
|
799
|
+
conf = Configuration.new do
|
800
|
+
alpha true
|
801
|
+
_read "bravo true\ncharlie true"
|
802
|
+
end
|
803
|
+
end.to_not raise_error
|
804
|
+
conf.should_not be_nil
|
805
|
+
conf.alpha.should be_true
|
806
|
+
conf.bravo.should be_true
|
807
|
+
conf.charlie.should be_true
|
808
|
+
end
|
809
|
+
|
810
|
+
it 'settings into the current configuration from a file (StringIO)' do
|
811
|
+
io = StringIO.new "bravo true
|
812
|
+
charlie true"
|
813
|
+
conf = nil
|
814
|
+
expect do
|
815
|
+
conf = Configuration.new do
|
816
|
+
alpha true
|
817
|
+
_file io
|
818
|
+
end
|
819
|
+
end.to_not raise_error
|
820
|
+
conf.should_not be_nil
|
821
|
+
conf.alpha.should be_true
|
822
|
+
conf.bravo.should be_true
|
823
|
+
conf.charlie.should be_true
|
824
|
+
end
|
825
|
+
|
826
|
+
it 'settings into a nested configuration from a string' do
|
827
|
+
conf = nil
|
828
|
+
expect do
|
829
|
+
conf = Configuration.new do
|
830
|
+
alpha true
|
831
|
+
bravo do
|
832
|
+
_read "charlie true\ndelta true"
|
833
|
+
end
|
834
|
+
echo { _read "foxtrot true\nhotel true" }
|
835
|
+
end
|
836
|
+
end.to_not raise_error
|
837
|
+
conf.should_not be_nil
|
838
|
+
conf.alpha.should be_true
|
839
|
+
conf.bravo.should be_a Configuration
|
840
|
+
conf.bravo.charlie.should be_true
|
841
|
+
conf.bravo.delta.should be_true
|
842
|
+
conf.bravo.alpha.should be_true
|
843
|
+
conf.echo.should be_a Configuration
|
844
|
+
conf.echo.foxtrot.should be_true
|
845
|
+
conf.echo.hotel.should be_true
|
846
|
+
conf.echo.alpha.should be_true
|
847
|
+
end
|
848
|
+
|
849
|
+
it 'settings into a nested configuration from a file (StringIO)' do
|
850
|
+
io1 = StringIO.new "charlie true
|
851
|
+
delta true"
|
852
|
+
io2 = StringIO.new "foxtrot true
|
853
|
+
hotel true"
|
854
|
+
conf = nil
|
855
|
+
expect do
|
856
|
+
conf = Configuration.new do
|
857
|
+
alpha true
|
858
|
+
bravo do
|
859
|
+
_file io1
|
860
|
+
end
|
861
|
+
echo { _file io2 }
|
862
|
+
end
|
863
|
+
end.to_not raise_error
|
864
|
+
conf.should_not be_nil
|
865
|
+
conf.alpha.should be_true
|
866
|
+
conf.bravo.should be_a Configuration
|
867
|
+
conf.bravo.charlie.should be_true
|
868
|
+
conf.bravo.delta.should be_true
|
869
|
+
conf.bravo.alpha.should be_true
|
870
|
+
conf.echo.should be_a Configuration
|
871
|
+
conf.echo.foxtrot.should be_true
|
872
|
+
conf.echo.hotel.should be_true
|
873
|
+
conf.echo.alpha.should be_true
|
874
|
+
end
|
875
|
+
|
876
|
+
end # can load
|
586
877
|
|
587
878
|
end # instance_eval DSL
|
588
879
|
|
589
880
|
end # mode of usage
|
590
881
|
|
591
|
-
context 'loads' do
|
592
|
-
|
593
|
-
it 'simple instance_eval DSL from string' do
|
594
|
-
string = "alpha 1
|
595
|
-
bravo 'two'
|
596
|
-
charlie 3.0
|
597
|
-
delta :four"
|
598
|
-
conf = nil
|
599
|
-
expect do
|
600
|
-
conf = Configuration.read string
|
601
|
-
end.to_not raise_error
|
602
|
-
conf.should_not be_nil
|
603
|
-
conf.alpha.should == 1 and conf.alpha.should be_a Fixnum
|
604
|
-
conf.bravo.should == "two" and conf.bravo.should be_a String
|
605
|
-
conf.charlie.should == 3.0 and conf.charlie.should be_a Float
|
606
|
-
conf.delta.should == :four and conf.delta.should be_a Symbol
|
607
|
-
end
|
608
|
-
|
609
|
-
it 'simple instance_eval DSL from file (by StringIO fake)' do
|
610
|
-
io = StringIO.new "alpha 1
|
611
|
-
bravo 'two'
|
612
|
-
charlie 3.0
|
613
|
-
delta :four"
|
614
|
-
conf = nil
|
615
|
-
expect do
|
616
|
-
conf = Configuration.file io
|
617
|
-
end.to_not raise_error
|
618
|
-
conf.should_not be_nil
|
619
|
-
conf.alpha.should == 1 and conf.alpha.should be_a Fixnum
|
620
|
-
conf.bravo.should == "two" and conf.bravo.should be_a String
|
621
|
-
conf.charlie.should == 3.0 and conf.charlie.should be_a Float
|
622
|
-
conf.delta.should == :four and conf.delta.should be_a Symbol
|
623
|
-
end
|
624
|
-
|
625
|
-
it 'simple instance_eval DSL from file (by mock and expected methods)' do
|
626
|
-
file = mock
|
627
|
-
file.should_receive( :respond_to? ).with( :read ).and_return true
|
628
|
-
file.should_receive( :read ).and_return "alpha 1
|
629
|
-
bravo 'two'
|
630
|
-
charlie 3.0
|
631
|
-
delta :four"
|
632
|
-
conf = nil
|
633
|
-
expect do
|
634
|
-
conf = Configuration.file file
|
635
|
-
end.to_not raise_error
|
636
|
-
conf.should_not be_nil
|
637
|
-
conf.alpha.should == 1 and conf.alpha.should be_a Fixnum
|
638
|
-
conf.bravo.should == "two" and conf.bravo.should be_a String
|
639
|
-
conf.charlie.should == 3.0 and conf.charlie.should be_a Float
|
640
|
-
conf.delta.should == :four and conf.delta.should be_a Symbol
|
641
|
-
end
|
642
|
-
|
643
|
-
it 'simple instance_eval DSL from filename (by expected methods)' do
|
644
|
-
File.should_receive( :read ).with( "filename" ).and_return "alpha 1
|
645
|
-
bravo 'two'
|
646
|
-
charlie 3.0
|
647
|
-
delta :four"
|
648
|
-
conf = nil
|
649
|
-
expect do
|
650
|
-
conf = Configuration.file "filename"
|
651
|
-
end.to_not raise_error
|
652
|
-
conf.should_not be_nil
|
653
|
-
conf.alpha.should == 1 and conf.alpha.should be_a Fixnum
|
654
|
-
conf.bravo.should == "two" and conf.bravo.should be_a String
|
655
|
-
conf.charlie.should == 3.0 and conf.charlie.should be_a Float
|
656
|
-
conf.delta.should == :four and conf.delta.should be_a Symbol
|
657
|
-
end
|
658
|
-
|
659
|
-
it 'complex instance_eval DSL from string' do
|
660
|
-
string = "alpha true
|
661
|
-
bravo do
|
662
|
-
charlie true
|
663
|
-
delta do
|
664
|
-
echo true
|
665
|
-
end
|
666
|
-
end"
|
667
|
-
conf = nil
|
668
|
-
expect do
|
669
|
-
conf = Configuration.read string
|
670
|
-
end.to_not raise_error
|
671
|
-
conf.should_not be_nil
|
672
|
-
conf.alpha.should be_true
|
673
|
-
conf.bravo.should be_a Configuration
|
674
|
-
conf.bravo.alpha should be_true
|
675
|
-
conf.bravo.charlie should be_true
|
676
|
-
conf.bravo.delta.should be_a Configuration
|
677
|
-
conf.bravo.delta.alpha.should be_true
|
678
|
-
conf.bravo.delta.charlie.should be_true
|
679
|
-
conf.bravo.delta.echo.should be_true
|
680
|
-
end
|
681
|
-
|
682
|
-
end # loads
|
683
|
-
|
684
|
-
it 'delegates hash methods to internal hash' do
|
685
|
-
conf = nil
|
686
|
-
expect do
|
687
|
-
conf = Configuration.new
|
688
|
-
conf.alpha 1
|
689
|
-
conf.bravo 2
|
690
|
-
conf.charlie 3
|
691
|
-
conf.delta 4
|
692
|
-
end.to_not raise_error
|
693
|
-
conf.should_not be_nil
|
694
|
-
sum = 0
|
695
|
-
expect do
|
696
|
-
conf.each { |k,v| sum += v }
|
697
|
-
end.to_not raise_error
|
698
|
-
sum.should == 10
|
699
|
-
conf.size.should == 4
|
700
|
-
end
|
701
|
-
|
702
882
|
end
|
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.10
|
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-05-
|
12
|
+
date: 2012-05-08 00:00:00.000000000 Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
@@ -43,6 +43,22 @@ dependencies:
|
|
43
43
|
- - ~>
|
44
44
|
- !ruby/object:Gem::Version
|
45
45
|
version: 0.9.2
|
46
|
+
- !ruby/object:Gem::Dependency
|
47
|
+
name: blankslate
|
48
|
+
requirement: !ruby/object:Gem::Requirement
|
49
|
+
none: false
|
50
|
+
requirements:
|
51
|
+
- - ~>
|
52
|
+
- !ruby/object:Gem::Version
|
53
|
+
version: 2.1.2.4
|
54
|
+
type: :runtime
|
55
|
+
prerelease: false
|
56
|
+
version_requirements: !ruby/object:Gem::Requirement
|
57
|
+
none: false
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: 2.1.2.4
|
46
62
|
description: A configuration DSL
|
47
63
|
email:
|
48
64
|
- gerard.fowley@iqeo.net
|
@@ -50,7 +66,6 @@ executables: []
|
|
50
66
|
extensions: []
|
51
67
|
extra_rdoc_files: []
|
52
68
|
files:
|
53
|
-
- .bundle/config
|
54
69
|
- .gitignore
|
55
70
|
- .rspec
|
56
71
|
- .rvmrc
|
@@ -71,6 +86,7 @@ files:
|
|
71
86
|
- pkg/iqeo-conf-0.0.6.gem
|
72
87
|
- pkg/iqeo-conf-0.0.7.gem
|
73
88
|
- pkg/iqeo-conf-0.0.8.gem
|
89
|
+
- pkg/iqeo-conf-0.0.9.gem
|
74
90
|
- spec/configuration_spec.rb
|
75
91
|
- spec/spec_helper.rb
|
76
92
|
homepage: http://iqeo.github.com/iqeo-conf
|
data/.bundle/config
DELETED