iqeo-conf 0.0.11 → 0.0.12
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/.yardoc/checksums +2 -2
- data/.yardoc/object_types +0 -0
- data/.yardoc/objects/root.dat +0 -0
- data/Gemfile.lock +9 -9
- data/README.md +2 -2
- data/doc/Iqeo/Configuration.html +236 -51
- data/doc/Iqeo.html +2 -2
- data/doc/_index.html +1 -1
- data/doc/file.README.html +3 -3
- data/doc/index.html +3 -3
- data/doc/method_list.html +32 -8
- data/doc/top-level-namespace.html +1 -1
- data/iqeo-conf.gemspec +1 -1
- data/lib/iqeo/configuration/version.rb +1 -1
- data/lib/iqeo/configuration.rb +22 -11
- data/spec/configuration_spec.rb +153 -212
- metadata +4 -4
data/doc/method_list.html
CHANGED
@@ -55,6 +55,14 @@
|
|
55
55
|
|
56
56
|
|
57
57
|
<li class="r2 ">
|
58
|
+
<span class='object_link'><a href="Iqeo/Configuration.html#_items-instance_method" title="Iqeo::Configuration#_items (method)">#_items</a></span>
|
59
|
+
|
60
|
+
<small>Iqeo::Configuration</small>
|
61
|
+
|
62
|
+
</li>
|
63
|
+
|
64
|
+
|
65
|
+
<li class="r1 ">
|
58
66
|
<span class='object_link'><a href="Iqeo/Configuration.html#_load-instance_method" title="Iqeo::Configuration#_load (method)">#_load</a></span>
|
59
67
|
|
60
68
|
<small>Iqeo::Configuration</small>
|
@@ -62,8 +70,16 @@
|
|
62
70
|
</li>
|
63
71
|
|
64
72
|
|
73
|
+
<li class="r2 ">
|
74
|
+
<span class='object_link'><a href="Iqeo/Configuration.html#_merge-instance_method" title="Iqeo::Configuration#_merge (method)">#_merge</a></span>
|
75
|
+
|
76
|
+
<small>Iqeo::Configuration</small>
|
77
|
+
|
78
|
+
</li>
|
79
|
+
|
80
|
+
|
65
81
|
<li class="r1 ">
|
66
|
-
<span class='object_link'><a href="Iqeo/Configuration.html#
|
82
|
+
<span class='object_link'><a href="Iqeo/Configuration.html#_merge%21-instance_method" title="Iqeo::Configuration#_merge! (method)">#_merge!</a></span>
|
67
83
|
|
68
84
|
<small>Iqeo::Configuration</small>
|
69
85
|
|
@@ -71,7 +87,7 @@
|
|
71
87
|
|
72
88
|
|
73
89
|
<li class="r2 ">
|
74
|
-
<span class='object_link'><a href="Iqeo/Configuration.html#
|
90
|
+
<span class='object_link'><a href="Iqeo/Configuration.html#_parent-instance_method" title="Iqeo::Configuration#_parent (method)">#_parent</a></span>
|
75
91
|
|
76
92
|
<small>Iqeo::Configuration</small>
|
77
93
|
|
@@ -79,7 +95,7 @@
|
|
79
95
|
|
80
96
|
|
81
97
|
<li class="r1 ">
|
82
|
-
<span class='object_link'><a href="Iqeo/Configuration.html#
|
98
|
+
<span class='object_link'><a href="Iqeo/Configuration.html#_read-instance_method" title="Iqeo::Configuration#_read (method)">#_read</a></span>
|
83
99
|
|
84
100
|
<small>Iqeo::Configuration</small>
|
85
101
|
|
@@ -87,7 +103,7 @@
|
|
87
103
|
|
88
104
|
|
89
105
|
<li class="r2 ">
|
90
|
-
<span class='object_link'><a href="Iqeo/Configuration.html#
|
106
|
+
<span class='object_link'><a href="Iqeo/Configuration.html#_set-instance_method" title="Iqeo::Configuration#_set (method)">#_set</a></span>
|
91
107
|
|
92
108
|
<small>Iqeo::Configuration</small>
|
93
109
|
|
@@ -95,7 +111,7 @@
|
|
95
111
|
|
96
112
|
|
97
113
|
<li class="r1 ">
|
98
|
-
<span class='object_link'><a href="Iqeo/Configuration.html#
|
114
|
+
<span class='object_link'><a href="Iqeo/Configuration.html#initialize-instance_method" title="Iqeo::Configuration#initialize (method)">#initialize</a></span>
|
99
115
|
|
100
116
|
<small>Iqeo::Configuration</small>
|
101
117
|
|
@@ -103,7 +119,7 @@
|
|
103
119
|
|
104
120
|
|
105
121
|
<li class="r2 ">
|
106
|
-
<span class='object_link'><a href="Iqeo/Configuration.html#
|
122
|
+
<span class='object_link'><a href="Iqeo/Configuration.html#load-class_method" title="Iqeo::Configuration.load (method)">load</a></span>
|
107
123
|
|
108
124
|
<small>Iqeo::Configuration</small>
|
109
125
|
|
@@ -111,7 +127,7 @@
|
|
111
127
|
|
112
128
|
|
113
129
|
<li class="r1 ">
|
114
|
-
<span class='object_link'><a href="Iqeo/Configuration.html#
|
130
|
+
<span class='object_link'><a href="Iqeo/Configuration.html#method_missing-instance_method" title="Iqeo::Configuration#method_missing (method)">#method_missing</a></span>
|
115
131
|
|
116
132
|
<small>Iqeo::Configuration</small>
|
117
133
|
|
@@ -119,7 +135,7 @@
|
|
119
135
|
|
120
136
|
|
121
137
|
<li class="r2 ">
|
122
|
-
<span class='object_link'><a href="Iqeo/Configuration.html#
|
138
|
+
<span class='object_link'><a href="Iqeo/Configuration.html#new_defer_block_for_parent-class_method" title="Iqeo::Configuration.new_defer_block_for_parent (method)">new_defer_block_for_parent</a></span>
|
123
139
|
|
124
140
|
<small>Iqeo::Configuration</small>
|
125
141
|
|
@@ -127,6 +143,14 @@
|
|
127
143
|
|
128
144
|
|
129
145
|
<li class="r1 ">
|
146
|
+
<span class='object_link'><a href="Iqeo/Configuration.html#read-class_method" title="Iqeo::Configuration.read (method)">read</a></span>
|
147
|
+
|
148
|
+
<small>Iqeo::Configuration</small>
|
149
|
+
|
150
|
+
</li>
|
151
|
+
|
152
|
+
|
153
|
+
<li class="r2 ">
|
130
154
|
<span class='object_link'><a href="Iqeo/Configuration.html#version-class_method" title="Iqeo::Configuration.version (method)">version</a></span>
|
131
155
|
|
132
156
|
<small>Iqeo::Configuration</small>
|
@@ -103,7 +103,7 @@
|
|
103
103
|
</div>
|
104
104
|
|
105
105
|
<div id="footer">
|
106
|
-
Generated on
|
106
|
+
Generated on Mon May 14 20:37:48 2012 by
|
107
107
|
<a href="http://yardoc.org" title="Yay! A Ruby Documentation Tool" target="_parent">yard</a>
|
108
108
|
0.8.1 (ruby-1.9.3).
|
109
109
|
</div>
|
data/iqeo-conf.gemspec
CHANGED
@@ -15,7 +15,7 @@ Gem::Specification.new do |gem|
|
|
15
15
|
gem.version = Iqeo::Configuration::VERSION
|
16
16
|
|
17
17
|
gem.add_development_dependency "rake", "~> 0.9.2"
|
18
|
-
gem.add_development_dependency "rspec", "~> 2.
|
18
|
+
gem.add_development_dependency "rspec", "~> 2.10.0"
|
19
19
|
gem.add_development_dependency "yard", "~> 0.8.1"
|
20
20
|
gem.add_development_dependency "rdoc", "~> 3.12.0"
|
21
21
|
gem.add_development_dependency "redcarpet", "~> 2.1.1"
|
data/lib/iqeo/configuration.rb
CHANGED
@@ -2,12 +2,9 @@
|
|
2
2
|
require_relative "configuration/version"
|
3
3
|
require_relative "configuration/hash_with_indifferent_access"
|
4
4
|
|
5
|
-
# todo: merge configurations
|
6
|
-
# todo: defaults
|
7
5
|
# todo: blank slate for DSL
|
8
|
-
# todo: rdoc documentation - yuck! try YARD & Markdown!
|
9
6
|
|
10
|
-
# Iqeo namespace
|
7
|
+
# Iqeo namespace
|
11
8
|
|
12
9
|
module Iqeo
|
13
10
|
|
@@ -52,8 +49,12 @@ module Iqeo
|
|
52
49
|
conf
|
53
50
|
end
|
54
51
|
|
55
|
-
def initialize &block
|
56
|
-
@
|
52
|
+
def initialize default = nil, &block
|
53
|
+
@_items = case
|
54
|
+
when default.kind_of?( HashWithIndifferentAccess ) then default
|
55
|
+
when default.kind_of?( Configuration ) then default._items
|
56
|
+
else HashWithIndifferentAccess.new
|
57
|
+
end
|
57
58
|
@_parent = nil
|
58
59
|
if block_given?
|
59
60
|
if block.arity == 1 # cannot set parent for yield blocks here as self is wrong !?
|
@@ -68,7 +69,7 @@ module Iqeo
|
|
68
69
|
end
|
69
70
|
|
70
71
|
def method_missing name, *values, &block
|
71
|
-
return @
|
72
|
+
return @_items.send( name, *values, &block ) if @_items.respond_to? name # @_items methods are highest priority
|
72
73
|
|
73
74
|
name = name.to_s.chomp('=')
|
74
75
|
|
@@ -85,7 +86,7 @@ module Iqeo
|
|
85
86
|
return _set name, values.first # set item to single value
|
86
87
|
end
|
87
88
|
|
88
|
-
attr_accessor :_parent
|
89
|
+
attr_accessor :_parent, :_items
|
89
90
|
|
90
91
|
def _set key, value
|
91
92
|
# fix: extend parenting for enumerable with configurations at arbitrary depth
|
@@ -93,7 +94,7 @@ module Iqeo
|
|
93
94
|
when value.kind_of?( Configuration ) then value._parent = self
|
94
95
|
when value.kind_of?( Enumerable ) then value.each { |v| v._parent = self if v.kind_of? Configuration }
|
95
96
|
end
|
96
|
-
@
|
97
|
+
@_items[key] = value
|
97
98
|
end
|
98
99
|
alias []= _set
|
99
100
|
|
@@ -104,8 +105,8 @@ module Iqeo
|
|
104
105
|
# Returns nil if key does not exist.
|
105
106
|
|
106
107
|
def _get key
|
107
|
-
return @
|
108
|
-
return @
|
108
|
+
return @_items[key] unless @_items[key].nil?
|
109
|
+
return @_items[key] if _parent.nil?
|
109
110
|
_parent._get key
|
110
111
|
end
|
111
112
|
alias [] _get
|
@@ -118,6 +119,16 @@ module Iqeo
|
|
118
119
|
_read file.respond_to?(:read) ? file.read : File.read(file)
|
119
120
|
end
|
120
121
|
|
122
|
+
def _merge! other
|
123
|
+
@_items.merge! other._items
|
124
|
+
self
|
125
|
+
end
|
126
|
+
|
127
|
+
def _merge other
|
128
|
+
self.dup._merge! other
|
129
|
+
end
|
130
|
+
|
131
|
+
|
121
132
|
end
|
122
133
|
|
123
134
|
end
|
data/spec/configuration_spec.rb
CHANGED
@@ -6,6 +6,39 @@ include Iqeo
|
|
6
6
|
|
7
7
|
describe Configuration do
|
8
8
|
|
9
|
+
def simple_eval_string
|
10
|
+
"alpha 1
|
11
|
+
bravo 'two'
|
12
|
+
charlie 3.0
|
13
|
+
delta :four"
|
14
|
+
end
|
15
|
+
|
16
|
+
def simple_explicit_configuration
|
17
|
+
conf = Configuration.new
|
18
|
+
conf.alpha 1
|
19
|
+
conf.bravo 'two'
|
20
|
+
conf.charlie 3.0
|
21
|
+
conf.delta :four
|
22
|
+
conf
|
23
|
+
end
|
24
|
+
|
25
|
+
def simple_configuration_example conf
|
26
|
+
conf.should_not be_nil
|
27
|
+
conf.alpha.should == 1 and conf.alpha.should be_a Fixnum
|
28
|
+
conf.bravo.should == "two" and conf.bravo.should be_a String
|
29
|
+
conf.charlie.should == 3.0 and conf.charlie.should be_a Float
|
30
|
+
conf.delta.should == :four and conf.delta.should be_a Symbol
|
31
|
+
end
|
32
|
+
|
33
|
+
def nested_configuration_example conf
|
34
|
+
conf.alpha.should be_true
|
35
|
+
conf.foxtrot.should be_true
|
36
|
+
simple_configuration_example conf.bravo
|
37
|
+
conf.bravo.foxtrot.should be_true
|
38
|
+
simple_configuration_example conf.echo
|
39
|
+
conf.echo.foxtrot.should be_true
|
40
|
+
end
|
41
|
+
|
9
42
|
it 'reports the correct version' do
|
10
43
|
Configuration.version.should == Configuration::VERSION
|
11
44
|
end
|
@@ -36,75 +69,42 @@ describe Configuration do
|
|
36
69
|
conf_new.should be conf_yielded
|
37
70
|
end
|
38
71
|
|
72
|
+
it 'accepts defaults from another configuration' do
|
73
|
+
conf = Configuration.new simple_explicit_configuration
|
74
|
+
simple_configuration_example conf
|
75
|
+
end
|
76
|
+
|
77
|
+
it 'overrides defaults from another configuration' do
|
78
|
+
conf_default = Configuration.new( simple_explicit_configuration ) { echo true }
|
79
|
+
conf_default.echo.should be_true
|
80
|
+
conf = Configuration.new( conf_default ) { echo false }
|
81
|
+
simple_configuration_example conf
|
82
|
+
conf.echo.should be_false
|
83
|
+
end
|
84
|
+
|
39
85
|
context 'can load' do
|
40
86
|
|
41
|
-
it 'simple
|
42
|
-
|
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
|
87
|
+
it 'simple eval DSL from string' do
|
88
|
+
simple_configuration_example Configuration.read simple_eval_string
|
55
89
|
end
|
56
90
|
|
57
|
-
it 'simple
|
58
|
-
|
59
|
-
bravo 'two'
|
60
|
-
charlie 3.0
|
61
|
-
delta :four"
|
62
|
-
conf = nil
|
63
|
-
expect do
|
64
|
-
conf = Configuration.load 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
|
91
|
+
it 'simple eval DSL from file (StringIO)' do
|
92
|
+
simple_configuration_example Configuration.load StringIO.new simple_eval_string
|
71
93
|
end
|
72
94
|
|
73
|
-
it 'simple
|
95
|
+
it 'simple eval DSL from file (mock & expected methods)' do
|
74
96
|
file = mock
|
75
97
|
file.should_receive( :respond_to? ).with( :read ).and_return true
|
76
|
-
file.should_receive( :read ).and_return
|
77
|
-
|
78
|
-
charlie 3.0
|
79
|
-
delta :four"
|
80
|
-
conf = nil
|
81
|
-
expect do
|
82
|
-
conf = Configuration.load 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
|
98
|
+
file.should_receive( :read ).and_return simple_eval_string
|
99
|
+
simple_configuration_example Configuration.load file
|
89
100
|
end
|
90
101
|
|
91
|
-
it 'simple
|
92
|
-
File.should_receive( :read ).with( "filename" ).and_return
|
93
|
-
|
94
|
-
charlie 3.0
|
95
|
-
delta :four"
|
96
|
-
conf = nil
|
97
|
-
expect do
|
98
|
-
conf = Configuration.load "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
|
102
|
+
it 'simple eval DSL from filename (expected methods)' do
|
103
|
+
File.should_receive( :read ).with( "filename" ).and_return simple_eval_string
|
104
|
+
simple_configuration_example Configuration.load "filename"
|
105
105
|
end
|
106
106
|
|
107
|
-
it 'complex
|
107
|
+
it 'complex eval DSL from string' do
|
108
108
|
string = "alpha true
|
109
109
|
bravo do
|
110
110
|
charlie true
|
@@ -112,10 +112,7 @@ describe Configuration do
|
|
112
112
|
echo true
|
113
113
|
end
|
114
114
|
end"
|
115
|
-
conf =
|
116
|
-
expect do
|
117
|
-
conf = Configuration.read string
|
118
|
-
end.to_not raise_error
|
115
|
+
conf = Configuration.read string
|
119
116
|
conf.should_not be_nil
|
120
117
|
conf.alpha.should be_true
|
121
118
|
conf.bravo.should be_a Configuration
|
@@ -134,19 +131,15 @@ describe Configuration do
|
|
134
131
|
context 'settings retrieval' do
|
135
132
|
|
136
133
|
it 'returns nil for non-existent settings' do
|
137
|
-
|
138
|
-
conf.not_a_setting.should be_nil
|
134
|
+
simple_explicit_configuration.not_a_setting.should be_nil
|
139
135
|
end
|
140
136
|
|
141
137
|
it 'delegates hash methods to internal hash' do
|
142
|
-
conf = nil
|
143
|
-
expect do
|
144
138
|
conf = Configuration.new
|
145
139
|
conf.alpha 1
|
146
140
|
conf.bravo 2
|
147
141
|
conf.charlie 3
|
148
142
|
conf.delta 4
|
149
|
-
end.to_not raise_error
|
150
143
|
conf.should_not be_nil
|
151
144
|
sum = 0
|
152
145
|
expect do
|
@@ -161,19 +154,7 @@ describe Configuration do
|
|
161
154
|
context 'single value setting' do
|
162
155
|
|
163
156
|
it 'accepts simple values' do
|
164
|
-
|
165
|
-
expect do
|
166
|
-
conf = Configuration.new
|
167
|
-
conf.alpha 1
|
168
|
-
conf.bravo 'two'
|
169
|
-
conf.charlie 3.0
|
170
|
-
conf.delta :four
|
171
|
-
end.to_not raise_error
|
172
|
-
conf.should_not be_nil
|
173
|
-
conf.alpha.should == 1 and conf.alpha.should be_a Fixnum
|
174
|
-
conf.bravo.should == 'two' and conf.bravo.should be_a String
|
175
|
-
conf.charlie.should == 3.0 and conf.charlie.should be_a Float
|
176
|
-
conf.delta.should == :four and conf.delta.should be_a Symbol
|
157
|
+
simple_configuration_example simple_explicit_configuration
|
177
158
|
end
|
178
159
|
|
179
160
|
it 'accepts complex values' do
|
@@ -521,83 +502,47 @@ describe Configuration do
|
|
521
502
|
context 'can load' do
|
522
503
|
|
523
504
|
it 'settings into the current configuration from a string' do
|
524
|
-
conf =
|
525
|
-
|
526
|
-
|
527
|
-
|
528
|
-
|
529
|
-
|
530
|
-
|
531
|
-
conf.should_not be_nil
|
532
|
-
conf.alpha.should be_true
|
533
|
-
conf.bravo.should be_true
|
534
|
-
conf.charlie.should be_true
|
505
|
+
conf = Configuration.new do |c|
|
506
|
+
c.alpha false
|
507
|
+
c._read simple_eval_string
|
508
|
+
c.echo true
|
509
|
+
end
|
510
|
+
simple_configuration_example conf
|
511
|
+
conf.echo.should be_true
|
535
512
|
end
|
536
513
|
|
537
514
|
it 'settings into the current configuration from a file (StringIO)' do
|
538
|
-
|
539
|
-
|
540
|
-
|
541
|
-
|
542
|
-
|
543
|
-
|
544
|
-
|
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
|
515
|
+
conf = Configuration.new do |c|
|
516
|
+
c.alpha false
|
517
|
+
c._load StringIO.new simple_eval_string
|
518
|
+
c.echo true
|
519
|
+
end
|
520
|
+
simple_configuration_example conf
|
521
|
+
conf.echo.should be_true
|
551
522
|
end
|
552
523
|
|
553
524
|
it 'settings into a nested configuration from a string' do
|
554
|
-
conf =
|
555
|
-
|
556
|
-
|
557
|
-
|
558
|
-
c.bravo do |x|
|
559
|
-
x._read "charlie true\ndelta true"
|
560
|
-
end
|
561
|
-
c.echo { |x| x._read "foxtrot true\nhotel true" }
|
525
|
+
conf = Configuration.new do |c|
|
526
|
+
c.alpha true
|
527
|
+
c.bravo do |x|
|
528
|
+
x._read simple_eval_string
|
562
529
|
end
|
563
|
-
|
564
|
-
|
565
|
-
|
566
|
-
conf
|
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
|
530
|
+
c.echo { |x| x._read simple_eval_string }
|
531
|
+
c.foxtrot true
|
532
|
+
end
|
533
|
+
nested_configuration_example conf
|
574
534
|
end
|
575
535
|
|
576
536
|
it 'settings into a nested configuration from a file (StringIO)' do
|
577
|
-
|
578
|
-
|
579
|
-
|
580
|
-
|
581
|
-
conf = nil
|
582
|
-
expect do
|
583
|
-
conf = Configuration.new do |c|
|
584
|
-
c.alpha true
|
585
|
-
c.bravo do |x|
|
586
|
-
x._load io1
|
587
|
-
end
|
588
|
-
c.echo { |x| x._load io2 }
|
537
|
+
conf = Configuration.new do |c|
|
538
|
+
c.alpha true
|
539
|
+
c.bravo do |x|
|
540
|
+
x._load StringIO.new simple_eval_string
|
589
541
|
end
|
590
|
-
|
591
|
-
|
592
|
-
|
593
|
-
conf
|
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
|
542
|
+
c.echo { |x| x._load StringIO.new simple_eval_string }
|
543
|
+
c.foxtrot true
|
544
|
+
end
|
545
|
+
nested_configuration_example conf
|
601
546
|
end
|
602
547
|
|
603
548
|
end # can load
|
@@ -794,83 +739,46 @@ describe Configuration do
|
|
794
739
|
context 'can load' do
|
795
740
|
|
796
741
|
it 'settings into the current configuration from a string' do
|
797
|
-
|
798
|
-
|
799
|
-
|
800
|
-
|
801
|
-
|
802
|
-
|
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
|
742
|
+
$simple_eval_string = simple_eval_string
|
743
|
+
conf = Configuration.new do
|
744
|
+
alpha true
|
745
|
+
_read $simple_eval_string
|
746
|
+
end
|
747
|
+
simple_configuration_example conf
|
808
748
|
end
|
809
749
|
|
810
750
|
it 'settings into the current configuration from a file (StringIO)' do
|
811
|
-
|
812
|
-
|
813
|
-
|
814
|
-
|
815
|
-
|
816
|
-
|
817
|
-
_load 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
|
751
|
+
$simple_eval_string = simple_eval_string
|
752
|
+
conf = Configuration.new do
|
753
|
+
alpha true
|
754
|
+
_load StringIO.new $simple_eval_string
|
755
|
+
end
|
756
|
+
simple_configuration_example conf
|
824
757
|
end
|
825
758
|
|
826
759
|
it 'settings into a nested configuration from a string' do
|
827
|
-
|
828
|
-
|
829
|
-
|
830
|
-
|
831
|
-
|
832
|
-
_read "charlie true\ndelta true"
|
833
|
-
end
|
834
|
-
echo { _read "foxtrot true\nhotel true" }
|
760
|
+
$simple_eval_string = simple_eval_string
|
761
|
+
conf = Configuration.new do
|
762
|
+
alpha true
|
763
|
+
bravo do
|
764
|
+
_read $simple_eval_string
|
835
765
|
end
|
836
|
-
|
837
|
-
|
838
|
-
|
839
|
-
conf
|
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
|
766
|
+
echo { _read $simple_eval_string }
|
767
|
+
foxtrot true
|
768
|
+
end
|
769
|
+
nested_configuration_example conf
|
847
770
|
end
|
848
771
|
|
849
772
|
it 'settings into a nested configuration from a file (StringIO)' do
|
850
|
-
|
851
|
-
|
852
|
-
|
853
|
-
|
854
|
-
conf = nil
|
855
|
-
expect do
|
856
|
-
conf = Configuration.new do
|
857
|
-
alpha true
|
858
|
-
bravo do
|
859
|
-
_load io1
|
860
|
-
end
|
861
|
-
echo { _load io2 }
|
773
|
+
conf = Configuration.new do
|
774
|
+
alpha true
|
775
|
+
bravo do
|
776
|
+
_load StringIO.new $simple_eval_string
|
862
777
|
end
|
863
|
-
|
864
|
-
|
865
|
-
|
866
|
-
conf
|
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
|
778
|
+
echo { _load StringIO.new $simple_eval_string }
|
779
|
+
foxtrot true
|
780
|
+
end
|
781
|
+
nested_configuration_example conf
|
874
782
|
end
|
875
783
|
|
876
784
|
end # can load
|
@@ -879,4 +787,37 @@ describe Configuration do
|
|
879
787
|
|
880
788
|
end # mode of usage
|
881
789
|
|
882
|
-
|
790
|
+
it 'can merge! configurations' do
|
791
|
+
orig = simple_explicit_configuration
|
792
|
+
orig.echo :original1
|
793
|
+
orig.foxtrot :original2
|
794
|
+
other = Configuration.new do
|
795
|
+
foxtrot :overridden
|
796
|
+
hotel :new
|
797
|
+
end
|
798
|
+
conf = orig._merge! other
|
799
|
+
simple_configuration_example conf
|
800
|
+
conf.echo.should be :original1
|
801
|
+
conf.hotel.should be :new
|
802
|
+
conf.foxtrot.should be :overridden
|
803
|
+
conf.should be orig
|
804
|
+
end
|
805
|
+
|
806
|
+
it 'can merge configurations' do
|
807
|
+
orig = simple_explicit_configuration
|
808
|
+
orig.echo :original1
|
809
|
+
orig.foxtrot :original2
|
810
|
+
other = Configuration.new do
|
811
|
+
foxtrot :overridden
|
812
|
+
hotel :new
|
813
|
+
end
|
814
|
+
conf = orig._merge other
|
815
|
+
simple_configuration_example conf
|
816
|
+
conf.echo.should be :original1
|
817
|
+
conf.hotel.should be :new
|
818
|
+
conf.foxtrot.should be :overridden
|
819
|
+
conf.should_not be orig
|
820
|
+
end
|
821
|
+
|
822
|
+
end
|
823
|
+
|