iqeo-conf 1.0.1 → 1.1.1
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.
- checksums.yaml +7 -0
- data/.gitignore +18 -4
- data/.rspec +2 -0
- data/.ruby-gemset +1 -0
- data/.ruby-version +1 -0
- data/Gemfile +9 -0
- data/Gemfile.lock +36 -21
- data/README.md +6 -1
- data/iqeo-conf.gemspec +10 -18
- data/lib/iqeo/configuration.rb +65 -19
- data/spec/configuration_spec.rb +242 -99
- data/spec/spec_helper.rb +7 -9
- metadata +21 -105
- data/lib/iqeo/configuration/version.rb +0 -3
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA256:
|
3
|
+
metadata.gz: 060e0a2e9dc2deb6a741f7d914a3b551ba80c9b4bbdf5436704e50b270406a5f
|
4
|
+
data.tar.gz: c8ad2d06e8b258f211c273635a65222d39cf2e2110306b178722899429b6783d
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 30bd99bf790acbf6008b8d36037ef76f350ca9792b067c82f46e742f9280bcd9c0a51925b17ff2d094e01c1108a09f761ee29949c65223e1dae396acefeb4418
|
7
|
+
data.tar.gz: ed1dce1772edc9d2dab9016f4b628b060ef923d1dc8fda19da6caf46f35a1338295f41f2551a5f23c94e62d6658d5049385a1ca5165e76f47817c2d89012e9d9
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/.ruby-gemset
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
iqeo-conf
|
data/.ruby-version
ADDED
@@ -0,0 +1 @@
|
|
1
|
+
ruby-3.4.4
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,34 +1,49 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
iqeo-conf (1.1.
|
4
|
+
iqeo-conf (1.1.1)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
rspec
|
21
|
-
|
22
|
-
|
23
|
-
|
9
|
+
date (3.4.1)
|
10
|
+
diff-lcs (1.6.2)
|
11
|
+
erb (5.0.2)
|
12
|
+
psych (5.2.6)
|
13
|
+
date
|
14
|
+
stringio
|
15
|
+
rake (13.3.0)
|
16
|
+
rdoc (6.14.2)
|
17
|
+
erb
|
18
|
+
psych (>= 4.0.0)
|
19
|
+
redcarpet (3.6.1)
|
20
|
+
rspec (3.13.1)
|
21
|
+
rspec-core (~> 3.13.0)
|
22
|
+
rspec-expectations (~> 3.13.0)
|
23
|
+
rspec-mocks (~> 3.13.0)
|
24
|
+
rspec-core (3.13.5)
|
25
|
+
rspec-support (~> 3.13.0)
|
26
|
+
rspec-expectations (3.13.5)
|
27
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
28
|
+
rspec-support (~> 3.13.0)
|
29
|
+
rspec-mocks (3.13.5)
|
30
|
+
diff-lcs (>= 1.2.0, < 2.0)
|
31
|
+
rspec-support (~> 3.13.0)
|
32
|
+
rspec-support (3.13.4)
|
33
|
+
stringio (3.1.7)
|
34
|
+
yard (0.9.37)
|
24
35
|
|
25
36
|
PLATFORMS
|
26
37
|
ruby
|
38
|
+
x86_64-linux
|
27
39
|
|
28
40
|
DEPENDENCIES
|
29
41
|
iqeo-conf!
|
30
|
-
rake (~>
|
31
|
-
rdoc (~>
|
32
|
-
redcarpet (~>
|
33
|
-
rspec (~>
|
34
|
-
yard (~> 0.
|
42
|
+
rake (~> 13.3)
|
43
|
+
rdoc (~> 6.14)
|
44
|
+
redcarpet (~> 3.6)
|
45
|
+
rspec (~> 3.13)
|
46
|
+
yard (~> 0.9.37)
|
47
|
+
|
48
|
+
BUNDLED WITH
|
49
|
+
2.6.7
|
data/README.md
CHANGED
@@ -1,5 +1,8 @@
|
|
1
1
|
# Iqeo::Configuration
|
2
2
|
|
3
|
+
[](http://badge.fury.io/rb/iqeo-conf)
|
4
|
+
[](https://travis-ci.org/iqeo/iqeo-conf)
|
5
|
+
|
3
6
|
A DSL representing configuration files.
|
4
7
|
|
5
8
|
## Installation
|
@@ -121,12 +124,14 @@ conf.collect { |key,value| value } # => [ 1, 2.0, :three, 'four' ]
|
|
121
124
|
* defaults
|
122
125
|
* merge configurations recursively
|
123
126
|
* blank slate for DSL
|
127
|
+
* wildcard * for chained usage: a.b.*.d
|
124
128
|
|
125
|
-
##
|
129
|
+
## Application
|
126
130
|
|
127
131
|
* Dynamic settings by '[]' & '[]=' & 'self'
|
128
132
|
* Multiple configuration files
|
129
133
|
* Hierarchial configuration files
|
134
|
+
* Validation: if a.b.*.d == true
|
130
135
|
|
131
136
|
## License
|
132
137
|
|
data/iqeo-conf.gemspec
CHANGED
@@ -1,23 +1,15 @@
|
|
1
1
|
# -*- encoding: utf-8 -*-
|
2
|
-
require File.expand_path('../lib/iqeo/configuration
|
2
|
+
require File.expand_path('../lib/iqeo/configuration', __FILE__)
|
3
3
|
|
4
4
|
Gem::Specification.new do |gem|
|
5
|
-
gem.authors = ["Gerard Fowley"]
|
6
|
-
gem.email = ["gerard.fowley@iqeo.net"]
|
7
|
-
gem.description = %q{A configuration DSL}
|
8
|
-
gem.summary = %q{A DSL for writing configuration files}
|
9
|
-
gem.homepage = "http://iqeo.github.com/iqeo-conf"
|
10
|
-
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
11
|
-
gem.files = `git ls-files`.split("\n")
|
12
|
-
gem.test_files = `git ls-files -- {spec}/*`.split("\n")
|
13
5
|
gem.name = "iqeo-conf"
|
14
|
-
gem.
|
15
|
-
gem.
|
16
|
-
|
17
|
-
gem.
|
18
|
-
gem.
|
19
|
-
gem.
|
20
|
-
gem.
|
21
|
-
gem.
|
22
|
-
|
6
|
+
gem.author = "Gerard Fowley"
|
7
|
+
gem.email = "gerard.fowley@iqeo.net"
|
8
|
+
gem.description = "A configuration DSL"
|
9
|
+
gem.summary = "A DSL for writing configuration files"
|
10
|
+
gem.homepage = "http://github.com/iqeo/iqeo-conf"
|
11
|
+
gem.license = "GPL-3.0"
|
12
|
+
gem.files = `git ls-files`.split("\n")
|
13
|
+
gem.metadata = { "rubygems_mfa_required" => "true" }
|
14
|
+
gem.version = Iqeo::Configuration::VERSION
|
23
15
|
end
|
data/lib/iqeo/configuration.rb
CHANGED
@@ -1,5 +1,5 @@
|
|
1
1
|
|
2
|
-
require_relative "configuration/version"
|
2
|
+
# require_relative "configuration/version"
|
3
3
|
require_relative "configuration/hash_with_indifferent_access"
|
4
4
|
|
5
5
|
# Iqeo namespace
|
@@ -24,7 +24,7 @@ module Iqeo
|
|
24
24
|
|
25
25
|
instance_methods_to_undef = %w(
|
26
26
|
! != !~ <=>
|
27
|
-
== ===
|
27
|
+
== === class
|
28
28
|
clone define_singleton_method display enum_for
|
29
29
|
eql? extend freeze frozen?
|
30
30
|
hash initialize_clone initialize_dup inspect
|
@@ -32,9 +32,8 @@ module Iqeo
|
|
32
32
|
instance_variable_set instance_variables method methods
|
33
33
|
nil? private_methods protected_methods public_method
|
34
34
|
public_methods public_send respond_to? respond_to_missing?
|
35
|
-
send singleton_class singleton_methods
|
36
|
-
|
37
|
-
trust untaint untrust untrusted?
|
35
|
+
send singleton_class singleton_methods
|
36
|
+
tap to_enum to_s
|
38
37
|
)
|
39
38
|
|
40
39
|
instance_methods_to_undef.each do |meth|
|
@@ -51,16 +50,18 @@ module Iqeo
|
|
51
50
|
|
52
51
|
# Returns Configuration version number.
|
53
52
|
|
53
|
+
VERSION = '1.1.1'
|
54
|
+
|
54
55
|
def self.version
|
55
|
-
|
56
|
+
VERSION
|
56
57
|
end
|
57
58
|
|
58
59
|
# Creates a new Configuration instance from string.
|
59
60
|
#
|
60
61
|
# Content should be in eval DSL format.
|
61
62
|
|
62
|
-
def self.read string
|
63
|
-
conf = self.new
|
63
|
+
def self.read string, options = {}
|
64
|
+
conf = self.new nil, options
|
64
65
|
conf.instance_eval string
|
65
66
|
conf
|
66
67
|
end
|
@@ -69,12 +70,12 @@ module Iqeo
|
|
69
70
|
#
|
70
71
|
# Content should be in eval DSL format.
|
71
72
|
|
72
|
-
def self.load file
|
73
|
+
def self.load file, options = {}
|
73
74
|
return self.read file.respond_to?(:read) ? file.read : File.read(file)
|
74
75
|
end
|
75
76
|
|
76
|
-
def self.new_defer_block_for_parent parent, &block
|
77
|
-
conf = Configuration.new
|
77
|
+
def self.new_defer_block_for_parent parent, options = {}, &block
|
78
|
+
conf = Configuration.new nil, options
|
78
79
|
conf._parent = parent
|
79
80
|
if block_given? && block.arity > 0
|
80
81
|
block.call(conf) # this is 'yield self' from the outside
|
@@ -82,9 +83,18 @@ module Iqeo
|
|
82
83
|
conf
|
83
84
|
end
|
84
85
|
|
85
|
-
|
86
|
+
OPTIONS = {
|
87
|
+
:blankslate => true,
|
88
|
+
:case_sensitive => true
|
89
|
+
}
|
90
|
+
|
91
|
+
attr_accessor :_parent, :_items, :_options
|
92
|
+
|
93
|
+
# todo: why can't :_parent= be protected ?
|
94
|
+
#protected :_parent, :_items, :_items= #, :_get, :[], :_set, :[]=
|
86
95
|
|
87
|
-
def initialize default = nil, &block
|
96
|
+
def initialize default = nil, options = {}, &block
|
97
|
+
_process_options options
|
88
98
|
@_items = HashWithIndifferentAccess.new
|
89
99
|
@_parent = nil
|
90
100
|
_merge! default if default.kind_of?( Configuration )
|
@@ -105,11 +115,11 @@ module Iqeo
|
|
105
115
|
|
106
116
|
name = name.to_s.chomp('=')
|
107
117
|
|
108
|
-
if block_given?
|
109
|
-
if block.arity == 1
|
110
|
-
return _set name, Configuration.new_defer_block_for_parent( self, &block )
|
118
|
+
if block_given? # block is a nested configuration
|
119
|
+
if block.arity == 1 # yield DSL needs deferred block to set parent without binding
|
120
|
+
return _set name, Configuration.new_defer_block_for_parent( self, @_options, &block )
|
111
121
|
else
|
112
|
-
return _set name, Configuration.new( &block )
|
122
|
+
return _set name, Configuration.new( nil, @_options, &block ) # eval DSL can set parent from block binding in initialize
|
113
123
|
end
|
114
124
|
end
|
115
125
|
|
@@ -161,9 +171,45 @@ module Iqeo
|
|
161
171
|
self.dup._merge! other
|
162
172
|
end
|
163
173
|
|
164
|
-
|
174
|
+
def _configurations
|
175
|
+
@_items.values.select { |value| value.kind_of? Configuration }
|
176
|
+
end
|
177
|
+
|
178
|
+
def _process_options options
|
179
|
+
@_options = OPTIONS.merge options
|
180
|
+
#_wipe if @_options[:blankslate] # todo: how to make blankslate optional ?
|
181
|
+
end
|
182
|
+
|
183
|
+
# todo: method '*' for wildcard dir glob like selections eg top.*.bottom ?
|
184
|
+
|
185
|
+
def *
|
186
|
+
ConfigurationDelegator.new _configurations
|
187
|
+
end
|
188
|
+
|
189
|
+
end
|
190
|
+
|
191
|
+
class ConfigurationDelegator # todo: inherit from < Blankslate ?
|
192
|
+
|
193
|
+
attr_reader :_confs
|
194
|
+
|
195
|
+
# protected :_confs
|
196
|
+
|
197
|
+
def initialize confs
|
198
|
+
@_confs = confs
|
199
|
+
end
|
165
200
|
|
166
|
-
|
201
|
+
def method_missing name, *values, &block
|
202
|
+
return @_confs.send( name, *values, &block ) if @_confs.respond_to? name # @_confs methods are highest priority
|
203
|
+
end
|
204
|
+
#alias [] method_missing # so we don't have to deal with [ and 'key' separately ( see alias [] _get in Configuration )
|
205
|
+
|
206
|
+
def empty?
|
207
|
+
@_confs.empty?
|
208
|
+
end
|
209
|
+
|
210
|
+
def *
|
211
|
+
ConfigurationDelegator.new( @_confs.inject([]) { |array,conf| array + conf._configurations } )
|
212
|
+
end
|
167
213
|
|
168
214
|
end
|
169
215
|
|
data/spec/configuration_spec.rb
CHANGED
@@ -24,25 +24,25 @@ describe Configuration do
|
|
24
24
|
|
25
25
|
def simple_configuration_example conf
|
26
26
|
conf.should_not be_nil
|
27
|
-
conf.alpha.should == 1 and conf.alpha.should be_a
|
27
|
+
conf.alpha.should == 1 and conf.alpha.should be_a Integer
|
28
28
|
conf.bravo.should == "two" and conf.bravo.should be_a String
|
29
29
|
conf.charlie.should == 3.0 and conf.charlie.should be_a Float
|
30
30
|
conf.delta.should == :four and conf.delta.should be_a Symbol
|
31
31
|
end
|
32
32
|
|
33
33
|
def nested_configuration_example conf
|
34
|
-
conf.alpha.should
|
35
|
-
conf.foxtrot.should
|
34
|
+
conf.alpha.should be true
|
35
|
+
conf.foxtrot.should be true
|
36
36
|
simple_configuration_example conf.bravo
|
37
|
-
conf.bravo.foxtrot.should
|
37
|
+
conf.bravo.foxtrot.should be true
|
38
38
|
simple_configuration_example conf.echo
|
39
|
-
conf.echo.foxtrot.should
|
39
|
+
conf.echo.foxtrot.should be true
|
40
40
|
end
|
41
41
|
|
42
42
|
context 'v1.0' do
|
43
43
|
|
44
44
|
it 'reports the correct version' do
|
45
|
-
Configuration.version.should ==
|
45
|
+
Configuration.version.should == '1.1.1'
|
46
46
|
end
|
47
47
|
|
48
48
|
context 'at creation' do
|
@@ -89,10 +89,10 @@ describe Configuration do
|
|
89
89
|
|
90
90
|
it 'overrides defaults from another configuration' do
|
91
91
|
conf_default = Configuration.new( simple_explicit_configuration ) { echo true }
|
92
|
-
conf_default.echo.should
|
92
|
+
conf_default.echo.should be true
|
93
93
|
conf = Configuration.new( conf_default ) { echo false }
|
94
94
|
simple_configuration_example conf
|
95
|
-
conf.echo.should
|
95
|
+
conf.echo.should be false
|
96
96
|
end
|
97
97
|
|
98
98
|
context 'can load' do
|
@@ -105,18 +105,6 @@ describe Configuration do
|
|
105
105
|
simple_configuration_example Configuration.load StringIO.new simple_eval_string
|
106
106
|
end
|
107
107
|
|
108
|
-
it 'simple eval DSL from file (mock & expected methods)' do
|
109
|
-
file = mock
|
110
|
-
file.should_receive( :respond_to? ).with( :read ).and_return true
|
111
|
-
file.should_receive( :read ).and_return simple_eval_string
|
112
|
-
simple_configuration_example Configuration.load file
|
113
|
-
end
|
114
|
-
|
115
|
-
it 'simple eval DSL from filename (expected methods)' do
|
116
|
-
File.should_receive( :read ).with( "filename" ).and_return simple_eval_string
|
117
|
-
simple_configuration_example Configuration.load "filename"
|
118
|
-
end
|
119
|
-
|
120
108
|
it 'complex eval DSL from string' do
|
121
109
|
string = "alpha true
|
122
110
|
bravo do
|
@@ -127,14 +115,14 @@ describe Configuration do
|
|
127
115
|
end"
|
128
116
|
conf = Configuration.read string
|
129
117
|
conf.should_not be_nil
|
130
|
-
conf.alpha.should
|
118
|
+
conf.alpha.should be true
|
131
119
|
conf.bravo.should be_a Configuration
|
132
|
-
conf.bravo.alpha
|
133
|
-
conf.bravo.charlie
|
120
|
+
conf.bravo.alpha.should be true
|
121
|
+
conf.bravo.charlie.should be true
|
134
122
|
conf.bravo.delta.should be_a Configuration
|
135
|
-
conf.bravo.delta.alpha.should
|
136
|
-
conf.bravo.delta.charlie.should
|
137
|
-
conf.bravo.delta.echo.should
|
123
|
+
conf.bravo.delta.alpha.should be true
|
124
|
+
conf.bravo.delta.charlie.should be true
|
125
|
+
conf.bravo.delta.echo.should be true
|
138
126
|
end
|
139
127
|
|
140
128
|
end # loads
|
@@ -250,7 +238,7 @@ describe Configuration do
|
|
250
238
|
conf.should_not be_nil
|
251
239
|
conf.alpha.should be_a Configuration
|
252
240
|
conf.alpha.bravo.should be_a Configuration
|
253
|
-
conf.alpha.bravo.charlie.should
|
241
|
+
conf.alpha.bravo.charlie.should be true
|
254
242
|
end
|
255
243
|
|
256
244
|
it 'knows its parent when referenced directly' do
|
@@ -278,12 +266,12 @@ describe Configuration do
|
|
278
266
|
conf.alpha.bravo.bottom = true
|
279
267
|
end.to_not raise_error
|
280
268
|
conf.should_not be_nil
|
281
|
-
conf.top.should
|
282
|
-
conf.alpha.top.should
|
283
|
-
conf.alpha.middle.should
|
284
|
-
conf.alpha.bravo.top.should
|
285
|
-
conf.alpha.bravo.middle.should
|
286
|
-
conf.alpha.bravo.bottom.should
|
269
|
+
conf.top.should be true
|
270
|
+
conf.alpha.top.should be true
|
271
|
+
conf.alpha.middle.should be true
|
272
|
+
conf.alpha.bravo.top.should be true
|
273
|
+
conf.alpha.bravo.middle.should be true
|
274
|
+
conf.alpha.bravo.bottom.should be true
|
287
275
|
end
|
288
276
|
|
289
277
|
it 'can override inherited settings' do
|
@@ -364,14 +352,14 @@ describe Configuration do
|
|
364
352
|
conf.bravo.delta.echo true
|
365
353
|
end.to_not raise_error
|
366
354
|
conf.should_not be_nil
|
367
|
-
conf.alpha.should
|
355
|
+
conf.alpha.should be true
|
368
356
|
conf.bravo.should be_a Configuration
|
369
|
-
conf.bravo.alpha
|
370
|
-
conf.bravo.charlie
|
357
|
+
conf.bravo.alpha.should be true
|
358
|
+
conf.bravo.charlie.should be true
|
371
359
|
conf.bravo.delta.should be_a Configuration
|
372
|
-
conf.bravo.delta.alpha.should
|
373
|
-
conf.bravo.delta.charlie.should
|
374
|
-
conf.bravo.delta.echo.should
|
360
|
+
conf.bravo.delta.alpha.should be true
|
361
|
+
conf.bravo.delta.charlie.should be true
|
362
|
+
conf.bravo.delta.echo.should be true
|
375
363
|
end
|
376
364
|
|
377
365
|
end # explicit
|
@@ -443,14 +431,14 @@ describe Configuration do
|
|
443
431
|
end
|
444
432
|
end.to_not raise_error
|
445
433
|
conf.should_not be_nil
|
446
|
-
conf.alpha.should
|
434
|
+
conf.alpha.should be true
|
447
435
|
conf.bravo.should be_a Configuration
|
448
|
-
conf.bravo.alpha
|
449
|
-
conf.bravo.charlie
|
436
|
+
conf.bravo.alpha.should be true
|
437
|
+
conf.bravo.charlie.should be true
|
450
438
|
conf.bravo.delta.should be_a Configuration
|
451
|
-
conf.bravo.delta.alpha.should
|
452
|
-
conf.bravo.delta.charlie.should
|
453
|
-
conf.bravo.delta.echo.should
|
439
|
+
conf.bravo.delta.alpha.should be true
|
440
|
+
conf.bravo.delta.charlie.should be true
|
441
|
+
conf.bravo.delta.echo.should be true
|
454
442
|
end
|
455
443
|
|
456
444
|
it 'supported via {..}' do
|
@@ -459,14 +447,14 @@ describe Configuration do
|
|
459
447
|
conf = Configuration.new { |c1| c1.alpha true ; c1.bravo { |c2| c2.charlie true ; c2.delta { |c3| c3.echo true } } }
|
460
448
|
end.to_not raise_error
|
461
449
|
conf.should_not be_nil
|
462
|
-
conf.alpha.should
|
450
|
+
conf.alpha.should be true
|
463
451
|
conf.bravo.should be_a Configuration
|
464
|
-
conf.bravo.alpha
|
465
|
-
conf.bravo.charlie
|
452
|
+
conf.bravo.alpha.should be true
|
453
|
+
conf.bravo.charlie.should be true
|
466
454
|
conf.bravo.delta.should be_a Configuration
|
467
|
-
conf.bravo.delta.alpha.should
|
468
|
-
conf.bravo.delta.charlie.should
|
469
|
-
conf.bravo.delta.echo.should
|
455
|
+
conf.bravo.delta.alpha.should be true
|
456
|
+
conf.bravo.delta.charlie.should be true
|
457
|
+
conf.bravo.delta.echo.should be true
|
470
458
|
end
|
471
459
|
|
472
460
|
it 'can refer to an inherited setting' do
|
@@ -486,17 +474,17 @@ describe Configuration do
|
|
486
474
|
end
|
487
475
|
end.to_not raise_error
|
488
476
|
conf.should_not be_nil
|
489
|
-
conf.alpha.should
|
477
|
+
conf.alpha.should be true
|
490
478
|
conf.bravo.should be_a Configuration
|
491
|
-
conf.bravo.alpha
|
492
|
-
conf.bravo.charlie
|
479
|
+
conf.bravo.alpha.should be true
|
480
|
+
conf.bravo.charlie.should be true
|
493
481
|
conf.bravo.delta.should be_a Configuration
|
494
|
-
conf.bravo.delta.alpha.should
|
495
|
-
conf.bravo.delta.charlie.should
|
496
|
-
conf.bravo.delta.echo.should
|
497
|
-
conf.bravo.delta.golf.should
|
498
|
-
conf.bravo.foxtrot.should
|
499
|
-
conf.hotel.should
|
482
|
+
conf.bravo.delta.alpha.should be true
|
483
|
+
conf.bravo.delta.charlie.should be true
|
484
|
+
conf.bravo.delta.echo.should be true
|
485
|
+
conf.bravo.delta.golf.should be true
|
486
|
+
conf.bravo.foxtrot.should be true
|
487
|
+
conf.hotel.should be true
|
500
488
|
end
|
501
489
|
|
502
490
|
end # nested configuration
|
@@ -510,7 +498,7 @@ describe Configuration do
|
|
510
498
|
c.echo true
|
511
499
|
end
|
512
500
|
simple_configuration_example conf
|
513
|
-
conf.echo.should
|
501
|
+
conf.echo.should be true
|
514
502
|
end
|
515
503
|
|
516
504
|
it 'settings into the current configuration from a file (StringIO)' do
|
@@ -520,7 +508,7 @@ describe Configuration do
|
|
520
508
|
c.echo true
|
521
509
|
end
|
522
510
|
simple_configuration_example conf
|
523
|
-
conf.echo.should
|
511
|
+
conf.echo.should be true
|
524
512
|
end
|
525
513
|
|
526
514
|
it 'settings into a nested configuration from a string' do
|
@@ -622,14 +610,14 @@ describe Configuration do
|
|
622
610
|
end
|
623
611
|
end.to_not raise_error
|
624
612
|
conf.should_not be_nil
|
625
|
-
conf.alpha.should
|
613
|
+
conf.alpha.should be true
|
626
614
|
conf.bravo.should be_a Configuration
|
627
|
-
conf.bravo.alpha
|
628
|
-
conf.bravo.charlie
|
615
|
+
conf.bravo.alpha.should be true
|
616
|
+
conf.bravo.charlie.should be true
|
629
617
|
conf.bravo.delta.should be_a Configuration
|
630
|
-
conf.bravo.delta.alpha.should
|
631
|
-
conf.bravo.delta.charlie.should
|
632
|
-
conf.bravo.delta.echo.should
|
618
|
+
conf.bravo.delta.alpha.should be true
|
619
|
+
conf.bravo.delta.charlie.should be true
|
620
|
+
conf.bravo.delta.echo.should be true
|
633
621
|
end
|
634
622
|
|
635
623
|
it 'supported via {..}' do
|
@@ -638,14 +626,14 @@ describe Configuration do
|
|
638
626
|
conf = Configuration.new { |c1| c1.alpha true ; c1.bravo { |c2| c2.charlie true ; c2.delta { |c3| c3.echo true } } }
|
639
627
|
end.to_not raise_error
|
640
628
|
conf.should_not be_nil
|
641
|
-
conf.alpha.should
|
629
|
+
conf.alpha.should be true
|
642
630
|
conf.bravo.should be_a Configuration
|
643
|
-
conf.bravo.alpha
|
644
|
-
conf.bravo.charlie
|
631
|
+
conf.bravo.alpha.should be true
|
632
|
+
conf.bravo.charlie.should be true
|
645
633
|
conf.bravo.delta.should be_a Configuration
|
646
|
-
conf.bravo.delta.alpha.should
|
647
|
-
conf.bravo.delta.charlie.should
|
648
|
-
conf.bravo.delta.echo.should
|
634
|
+
conf.bravo.delta.alpha.should be true
|
635
|
+
conf.bravo.delta.charlie.should be true
|
636
|
+
conf.bravo.delta.echo.should be true
|
649
637
|
end
|
650
638
|
|
651
639
|
it 'can refer to an inherited setting' do
|
@@ -665,17 +653,17 @@ describe Configuration do
|
|
665
653
|
end
|
666
654
|
end.to_not raise_error
|
667
655
|
conf.should_not be_nil
|
668
|
-
conf.alpha.should
|
656
|
+
conf.alpha.should be true
|
669
657
|
conf.bravo.should be_a Configuration
|
670
|
-
conf.bravo.alpha
|
671
|
-
conf.bravo.charlie
|
658
|
+
conf.bravo.alpha.should be true
|
659
|
+
conf.bravo.charlie.should be true
|
672
660
|
conf.bravo.delta.should be_a Configuration
|
673
|
-
conf.bravo.delta.alpha.should
|
674
|
-
conf.bravo.delta.charlie.should
|
675
|
-
conf.bravo.delta.echo.should
|
676
|
-
conf.bravo.delta.golf.should
|
677
|
-
conf.bravo.foxtrot.should
|
678
|
-
conf.hotel.should
|
661
|
+
conf.bravo.delta.alpha.should be true
|
662
|
+
conf.bravo.delta.charlie.should be true
|
663
|
+
conf.bravo.delta.echo.should be true
|
664
|
+
conf.bravo.delta.golf.should be true
|
665
|
+
conf.bravo.foxtrot.should be true
|
666
|
+
conf.hotel.should be true
|
679
667
|
end
|
680
668
|
|
681
669
|
end # nested configuration
|
@@ -694,9 +682,9 @@ describe Configuration do
|
|
694
682
|
end
|
695
683
|
end.to_not raise_error
|
696
684
|
conf.should_not be_nil
|
697
|
-
conf.alpha.should
|
698
|
-
conf.bravo.should
|
699
|
-
conf.charlie.should
|
685
|
+
conf.alpha.should be true
|
686
|
+
conf.bravo.should be true
|
687
|
+
conf.charlie.should be true
|
700
688
|
end
|
701
689
|
|
702
690
|
it 'name can be a setting' do
|
@@ -711,9 +699,9 @@ describe Configuration do
|
|
711
699
|
end
|
712
700
|
end.to_not raise_error
|
713
701
|
conf.should_not be_nil
|
714
|
-
conf.alpha.should
|
715
|
-
conf.bravo.should
|
716
|
-
conf.charlie.should
|
702
|
+
conf.alpha.should be true
|
703
|
+
conf.bravo.should be true
|
704
|
+
conf.charlie.should be true
|
717
705
|
conf.setting1.should == 'bravo'
|
718
706
|
conf.setting2.should == 'charlie'
|
719
707
|
end
|
@@ -730,10 +718,10 @@ describe Configuration do
|
|
730
718
|
end
|
731
719
|
end.to_not raise_error
|
732
720
|
conf.should_not be_nil
|
733
|
-
conf.alpha.should
|
721
|
+
conf.alpha.should be true
|
734
722
|
conf.bravo.should be_a Configuration
|
735
|
-
conf.bravo.alpha
|
736
|
-
conf.bravo.charlie
|
723
|
+
conf.bravo.alpha.should be true
|
724
|
+
conf.bravo.charlie.should be true
|
737
725
|
end
|
738
726
|
|
739
727
|
end # dynamic setting
|
@@ -951,13 +939,168 @@ describe Configuration do
|
|
951
939
|
|
952
940
|
end # "v1.0"
|
953
941
|
|
954
|
-
|
955
|
-
|
956
|
-
|
957
|
-
|
958
|
-
|
959
|
-
|
960
|
-
|
942
|
+
def simple_config_1
|
943
|
+
Configuration.new do
|
944
|
+
alpha 1
|
945
|
+
bravo 'one'
|
946
|
+
charlie 1.0
|
947
|
+
delta :one
|
948
|
+
end
|
949
|
+
end
|
950
|
+
|
951
|
+
def simple_config_1_example conf
|
952
|
+
conf.should_not be_nil
|
953
|
+
conf.alpha.should == 1 and conf.alpha.should be_a Integer
|
954
|
+
conf.bravo.should == "one" and conf.bravo.should be_a String
|
955
|
+
conf.charlie.should == 1.0 and conf.charlie.should be_a Float
|
956
|
+
conf.delta.should == :one and conf.delta.should be_a Symbol
|
957
|
+
end
|
958
|
+
|
959
|
+
def simple_config_2
|
960
|
+
Configuration.new do
|
961
|
+
echo 2
|
962
|
+
foxtrot 'two'
|
963
|
+
hotel 2.0
|
964
|
+
india :two
|
965
|
+
end
|
966
|
+
end
|
967
|
+
|
968
|
+
def simple_config_2_example conf
|
969
|
+
conf.should_not be_nil
|
970
|
+
conf.echo.should == 2 and conf.echo.should be_a Integer
|
971
|
+
conf.foxtrot.should == "two" and conf.foxtrot.should be_a String
|
972
|
+
conf.hotel.should == 2.0 and conf.hotel.should be_a Float
|
973
|
+
conf.india.should == :two and conf.india.should be_a Symbol
|
974
|
+
conf['echo']
|
975
|
+
#and conf[:echo].should be_a Integer
|
976
|
+
|
977
|
+
end
|
978
|
+
|
979
|
+
def simple_config_3
|
980
|
+
Configuration.new do
|
981
|
+
juliet 3
|
982
|
+
kilo 'three'
|
983
|
+
lima 3.0
|
984
|
+
mike :three
|
985
|
+
end
|
986
|
+
end
|
987
|
+
|
988
|
+
def simple_config_3_example conf
|
989
|
+
conf.should_not be_nil
|
990
|
+
conf.juliet.should == 3 and conf.juliet.should be_a Integer
|
991
|
+
conf.kilo.should == "three" and conf.kilo.should be_a String
|
992
|
+
conf.lima.should == 3.0 and conf.lima.should be_a Float
|
993
|
+
conf.mike.should == :three and conf.mike.should be_a Symbol
|
994
|
+
end
|
995
|
+
|
996
|
+
context 'v1.1' do
|
997
|
+
|
998
|
+
context 'options' do
|
999
|
+
|
1000
|
+
it 'have defaults at Configuration creation' do
|
1001
|
+
conf = Configuration.new
|
1002
|
+
conf._options[:blankslate].should be true
|
1003
|
+
conf._options[:case_sensitive].should be true
|
1004
|
+
end
|
1005
|
+
|
1006
|
+
it 'are accepted at Configuration creation' do
|
1007
|
+
conf = Configuration.new nil, :blankslate => false, :case_sensitive => false
|
1008
|
+
conf._options[:blankslate].should be false
|
1009
|
+
conf._options[:case_sensitive].should be false
|
1010
|
+
end
|
1011
|
+
|
1012
|
+
end
|
1013
|
+
|
1014
|
+
context 'wildcard *' do
|
1015
|
+
|
1016
|
+
it 'returns an empty ConfigurationDelegator for subject with no child configurations' do
|
1017
|
+
conf = simple_config_1
|
1018
|
+
simple_config_1_example conf
|
1019
|
+
delegator = conf.*
|
1020
|
+
delegator.should be_a ConfigurationDelegator
|
1021
|
+
delegator.should be_empty
|
1022
|
+
end
|
1023
|
+
|
1024
|
+
it 'returns ConfigurationDelegator containing child configurations for subject' do
|
1025
|
+
conf = simple_config_1
|
1026
|
+
conf.nested2 = simple_config_2
|
1027
|
+
conf.nested3 = simple_config_3
|
1028
|
+
simple_config_1_example conf
|
1029
|
+
simple_config_2_example conf.nested2
|
1030
|
+
simple_config_3_example conf.nested3
|
1031
|
+
delegator = conf.*
|
1032
|
+
delegator.should be_a ConfigurationDelegator
|
1033
|
+
delegator.size.should be 2
|
1034
|
+
delegator[0].should be conf.nested2
|
1035
|
+
delegator[1].should be conf.nested3
|
1036
|
+
end
|
1037
|
+
|
1038
|
+
end
|
1039
|
+
|
1040
|
+
context 'ConfigurationDelegator' do
|
1041
|
+
|
1042
|
+
it 'can be created with no child configurations' do
|
1043
|
+
delegator = ConfigurationDelegator.new []
|
1044
|
+
delegator.should be_a ConfigurationDelegator
|
1045
|
+
delegator.should be_empty
|
1046
|
+
end
|
1047
|
+
|
1048
|
+
context 'wildcard *' do
|
1049
|
+
|
1050
|
+
# todo: question : should wildcard return nil for already empty ConfigurationDelegator / overshoot ?
|
1051
|
+
|
1052
|
+
it 'returns an empty ConfigurationDelegator for ConfigurationDelegator with no child configurations' do
|
1053
|
+
conf = simple_config_1
|
1054
|
+
conf.nested2 = simple_config_2
|
1055
|
+
conf.nested3 = simple_config_3
|
1056
|
+
simple_config_1_example conf
|
1057
|
+
simple_config_2_example conf.nested2
|
1058
|
+
simple_config_3_example conf.nested3
|
1059
|
+
delegator = conf.*.*
|
1060
|
+
delegator.should be_a ConfigurationDelegator
|
1061
|
+
delegator.should be_empty
|
1062
|
+
end
|
1063
|
+
|
1064
|
+
it 'returns an empty ConfigurationDelegator when overshoots' do
|
1065
|
+
conf = simple_config_1
|
1066
|
+
conf.nested2 = simple_config_2
|
1067
|
+
conf.nested3 = simple_config_3
|
1068
|
+
simple_config_1_example conf
|
1069
|
+
simple_config_2_example conf.nested2
|
1070
|
+
simple_config_3_example conf.nested3
|
1071
|
+
delegator = conf.*.*.*.*.*.*.*.*.*
|
1072
|
+
delegator.should be_a ConfigurationDelegator
|
1073
|
+
delegator.should be_empty
|
1074
|
+
end
|
1075
|
+
|
1076
|
+
it 'returns ConfigurationDelegator containing child configurations for ConfigurationDelegator' do
|
1077
|
+
conf = simple_config_1
|
1078
|
+
conf.nested2 = simple_config_2
|
1079
|
+
conf.nested3 = simple_config_3
|
1080
|
+
conf.nested2.nested2 = simple_config_2
|
1081
|
+
conf.nested2.nested3 = simple_config_3
|
1082
|
+
conf.nested3.nested2 = simple_config_2
|
1083
|
+
conf.nested3.nested3 = simple_config_3
|
1084
|
+
simple_config_1_example conf
|
1085
|
+
simple_config_2_example conf.nested2
|
1086
|
+
simple_config_2_example conf.nested2.nested2
|
1087
|
+
simple_config_2_example conf.nested3.nested2
|
1088
|
+
simple_config_3_example conf.nested3
|
1089
|
+
simple_config_3_example conf.nested2.nested3
|
1090
|
+
simple_config_3_example conf.nested3.nested3
|
1091
|
+
delegator = conf.*.*
|
1092
|
+
delegator.size.should be 4
|
1093
|
+
delegator[0].should be conf.nested2.nested2
|
1094
|
+
delegator[1].should be conf.nested2.nested3
|
1095
|
+
delegator[2].should be conf.nested3.nested2
|
1096
|
+
delegator[3].should be conf.nested3.nested3
|
1097
|
+
end
|
1098
|
+
|
1099
|
+
end # wildcard *
|
1100
|
+
|
1101
|
+
end # ConfigurationDelagator
|
1102
|
+
|
1103
|
+
end #v1.1
|
961
1104
|
|
962
1105
|
end
|
963
1106
|
|
data/spec/spec_helper.rb
CHANGED
@@ -1,11 +1,9 @@
|
|
1
|
-
# This file was generated by the `rspec --init` command. Conventionally, all
|
2
|
-
# specs live under a `spec` directory, which RSpec adds to the `$LOAD_PATH`.
|
3
|
-
# Require this file using `require "spec_helper.rb"` to ensure that it is only
|
4
|
-
# loaded once.
|
5
|
-
#
|
6
|
-
# See http://rubydoc.info/gems/rspec-core/RSpec/Core/Configuration
|
7
1
|
RSpec.configure do |config|
|
8
|
-
config.
|
9
|
-
|
10
|
-
|
2
|
+
config.expect_with :rspec do |expectations|
|
3
|
+
expectations.syntax = [ :should, :expect ]
|
4
|
+
end
|
5
|
+
config.mock_with :rspec do |mocks|
|
6
|
+
mocks.syntax = [ :should, :expect ]
|
7
|
+
end
|
11
8
|
end
|
9
|
+
|
metadata
CHANGED
@@ -1,108 +1,28 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: iqeo-conf
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.
|
5
|
-
prerelease:
|
4
|
+
version: 1.1.1
|
6
5
|
platform: ruby
|
7
6
|
authors:
|
8
7
|
- Gerard Fowley
|
9
|
-
autorequire:
|
10
8
|
bindir: bin
|
11
9
|
cert_chain: []
|
12
|
-
date:
|
13
|
-
dependencies:
|
14
|
-
- !ruby/object:Gem::Dependency
|
15
|
-
name: rake
|
16
|
-
requirement: !ruby/object:Gem::Requirement
|
17
|
-
none: false
|
18
|
-
requirements:
|
19
|
-
- - ~>
|
20
|
-
- !ruby/object:Gem::Version
|
21
|
-
version: 0.9.2
|
22
|
-
type: :development
|
23
|
-
prerelease: false
|
24
|
-
version_requirements: !ruby/object:Gem::Requirement
|
25
|
-
none: false
|
26
|
-
requirements:
|
27
|
-
- - ~>
|
28
|
-
- !ruby/object:Gem::Version
|
29
|
-
version: 0.9.2
|
30
|
-
- !ruby/object:Gem::Dependency
|
31
|
-
name: rspec
|
32
|
-
requirement: !ruby/object:Gem::Requirement
|
33
|
-
none: false
|
34
|
-
requirements:
|
35
|
-
- - ~>
|
36
|
-
- !ruby/object:Gem::Version
|
37
|
-
version: 2.10.0
|
38
|
-
type: :development
|
39
|
-
prerelease: false
|
40
|
-
version_requirements: !ruby/object:Gem::Requirement
|
41
|
-
none: false
|
42
|
-
requirements:
|
43
|
-
- - ~>
|
44
|
-
- !ruby/object:Gem::Version
|
45
|
-
version: 2.10.0
|
46
|
-
- !ruby/object:Gem::Dependency
|
47
|
-
name: yard
|
48
|
-
requirement: !ruby/object:Gem::Requirement
|
49
|
-
none: false
|
50
|
-
requirements:
|
51
|
-
- - ~>
|
52
|
-
- !ruby/object:Gem::Version
|
53
|
-
version: 0.8.1
|
54
|
-
type: :development
|
55
|
-
prerelease: false
|
56
|
-
version_requirements: !ruby/object:Gem::Requirement
|
57
|
-
none: false
|
58
|
-
requirements:
|
59
|
-
- - ~>
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: 0.8.1
|
62
|
-
- !ruby/object:Gem::Dependency
|
63
|
-
name: rdoc
|
64
|
-
requirement: !ruby/object:Gem::Requirement
|
65
|
-
none: false
|
66
|
-
requirements:
|
67
|
-
- - ~>
|
68
|
-
- !ruby/object:Gem::Version
|
69
|
-
version: 3.12.0
|
70
|
-
type: :development
|
71
|
-
prerelease: false
|
72
|
-
version_requirements: !ruby/object:Gem::Requirement
|
73
|
-
none: false
|
74
|
-
requirements:
|
75
|
-
- - ~>
|
76
|
-
- !ruby/object:Gem::Version
|
77
|
-
version: 3.12.0
|
78
|
-
- !ruby/object:Gem::Dependency
|
79
|
-
name: redcarpet
|
80
|
-
requirement: !ruby/object:Gem::Requirement
|
81
|
-
none: false
|
82
|
-
requirements:
|
83
|
-
- - ~>
|
84
|
-
- !ruby/object:Gem::Version
|
85
|
-
version: 2.1.1
|
86
|
-
type: :development
|
87
|
-
prerelease: false
|
88
|
-
version_requirements: !ruby/object:Gem::Requirement
|
89
|
-
none: false
|
90
|
-
requirements:
|
91
|
-
- - ~>
|
92
|
-
- !ruby/object:Gem::Version
|
93
|
-
version: 2.1.1
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
11
|
+
dependencies: []
|
94
12
|
description: A configuration DSL
|
95
|
-
email:
|
96
|
-
- gerard.fowley@iqeo.net
|
13
|
+
email: gerard.fowley@iqeo.net
|
97
14
|
executables: []
|
98
15
|
extensions: []
|
99
16
|
extra_rdoc_files: []
|
100
17
|
files:
|
101
|
-
- .gitignore
|
102
|
-
- .
|
103
|
-
- .
|
104
|
-
- .
|
105
|
-
- .yardoc/
|
18
|
+
- ".gitignore"
|
19
|
+
- ".rspec"
|
20
|
+
- ".ruby-gemset"
|
21
|
+
- ".ruby-version"
|
22
|
+
- ".yardoc/checksums"
|
23
|
+
- ".yardoc/object_types"
|
24
|
+
- ".yardoc/objects/root.dat"
|
25
|
+
- ".yardoc/proxy_types"
|
106
26
|
- Gemfile
|
107
27
|
- Gemfile.lock
|
108
28
|
- LICENSE
|
@@ -128,32 +48,28 @@ files:
|
|
128
48
|
- iqeo-conf.gemspec
|
129
49
|
- lib/iqeo/configuration.rb
|
130
50
|
- lib/iqeo/configuration/hash_with_indifferent_access.rb
|
131
|
-
- lib/iqeo/configuration/version.rb
|
132
51
|
- spec/configuration_spec.rb
|
133
52
|
- spec/spec_helper.rb
|
134
|
-
homepage: http://
|
135
|
-
licenses:
|
136
|
-
|
53
|
+
homepage: http://github.com/iqeo/iqeo-conf
|
54
|
+
licenses:
|
55
|
+
- GPL-3.0
|
56
|
+
metadata:
|
57
|
+
rubygems_mfa_required: 'true'
|
137
58
|
rdoc_options: []
|
138
59
|
require_paths:
|
139
60
|
- lib
|
140
61
|
required_ruby_version: !ruby/object:Gem::Requirement
|
141
|
-
none: false
|
142
62
|
requirements:
|
143
|
-
- -
|
63
|
+
- - ">="
|
144
64
|
- !ruby/object:Gem::Version
|
145
65
|
version: '0'
|
146
66
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
147
|
-
none: false
|
148
67
|
requirements:
|
149
|
-
- -
|
68
|
+
- - ">="
|
150
69
|
- !ruby/object:Gem::Version
|
151
70
|
version: '0'
|
152
71
|
requirements: []
|
153
|
-
|
154
|
-
|
155
|
-
signing_key:
|
156
|
-
specification_version: 3
|
72
|
+
rubygems_version: 3.6.7
|
73
|
+
specification_version: 4
|
157
74
|
summary: A DSL for writing configuration files
|
158
75
|
test_files: []
|
159
|
-
has_rdoc:
|