iqeo-conf 0.0.1 → 0.0.2
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/.bundle/config +2 -1
- data/.gitignore +1 -0
- data/.rspec +2 -0
- data/Gemfile.lock +13 -1
- data/README.md +28 -23
- data/Rakefile +6 -1
- data/iqeo-conf.gemspec +5 -1
- data/lib/iqeo/configuration/version.rb +1 -1
- data/lib/iqeo/configuration.rb +25 -11
- data/pkg/iqeo-conf-0.0.1.gem +0 -0
- data/pkg/iqeo-conf-0.0.2.gem +0 -0
- data/spec/configuration_spec.rb +280 -0
- data/spec/spec_helper.rb +11 -0
- metadata +40 -3
data/.bundle/config
CHANGED
@@ -1 +1,2 @@
|
|
1
|
-
---
|
1
|
+
---
|
2
|
+
BUNDLE_BIN: bin
|
data/.gitignore
CHANGED
data/.rspec
ADDED
data/Gemfile.lock
CHANGED
@@ -1,14 +1,26 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
iqeo-conf (0.0.
|
4
|
+
iqeo-conf (0.0.2)
|
5
5
|
|
6
6
|
GEM
|
7
7
|
remote: https://rubygems.org/
|
8
8
|
specs:
|
9
|
+
diff-lcs (1.1.3)
|
10
|
+
rake (0.9.2.2)
|
11
|
+
rspec (2.9.0)
|
12
|
+
rspec-core (~> 2.9.0)
|
13
|
+
rspec-expectations (~> 2.9.0)
|
14
|
+
rspec-mocks (~> 2.9.0)
|
15
|
+
rspec-core (2.9.0)
|
16
|
+
rspec-expectations (2.9.1)
|
17
|
+
diff-lcs (~> 1.1.3)
|
18
|
+
rspec-mocks (2.9.0)
|
9
19
|
|
10
20
|
PLATFORMS
|
11
21
|
ruby
|
12
22
|
|
13
23
|
DEPENDENCIES
|
14
24
|
iqeo-conf!
|
25
|
+
rake (~> 0.9.2)
|
26
|
+
rspec (~> 2.9.0)
|
data/README.md
CHANGED
@@ -4,19 +4,7 @@ A DSL for writing configuration files.
|
|
4
4
|
|
5
5
|
## Installation
|
6
6
|
|
7
|
-
|
8
|
-
|
9
|
-
```
|
10
|
-
gem 'iqeo-conf'
|
11
|
-
```
|
12
|
-
|
13
|
-
And then execute:
|
14
|
-
|
15
|
-
```
|
16
|
-
$ bundle
|
17
|
-
```
|
18
|
-
|
19
|
-
Or install it yourself as:
|
7
|
+
It's a gem...
|
20
8
|
|
21
9
|
```
|
22
10
|
$ gem install iqeo-conf
|
@@ -26,9 +14,13 @@ $ gem install iqeo-conf
|
|
26
14
|
|
27
15
|
### Defining a configuration
|
28
16
|
|
17
|
+
```ruby
|
18
|
+
require 'iqeo/configuration'
|
19
|
+
```
|
20
|
+
|
29
21
|
Set values...
|
30
22
|
|
31
|
-
####
|
23
|
+
#### Directly on a configuration object
|
32
24
|
|
33
25
|
```ruby
|
34
26
|
conf = Iqeo::Configuration.new
|
@@ -41,7 +33,7 @@ conf.charlie { :a => 1, :b => 2, :c => 3 }
|
|
41
33
|
conf.delta [ 1, 2, 3 ]
|
42
34
|
```
|
43
35
|
|
44
|
-
#### Configuration DSL
|
36
|
+
#### Configuration DSL block yield style
|
45
37
|
|
46
38
|
```ruby
|
47
39
|
conf = Iqeo::Configuration.new do |c|
|
@@ -54,7 +46,7 @@ conf = Iqeo::Configuration.new do |c|
|
|
54
46
|
end
|
55
47
|
```
|
56
48
|
|
57
|
-
### Configuration DSL
|
49
|
+
### Configuration DSL instance_eval style
|
58
50
|
|
59
51
|
```ruby
|
60
52
|
conf = Iqeo::Configuration.new do
|
@@ -78,13 +70,26 @@ conf.charlie => { :a => 1, :b => 2, :c => 3 }
|
|
78
70
|
conf.delta => [ 1, 2, 3 ]
|
79
71
|
```
|
80
72
|
|
81
|
-
##
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
73
|
+
## Other features
|
74
|
+
|
75
|
+
This README may not be complete, see rspec tests for all features.
|
76
|
+
|
77
|
+
## Todo
|
78
|
+
|
79
|
+
* Hash operators [] & []= - done!
|
80
|
+
* Nested configurations - done!
|
81
|
+
* Nested configurations inherit settings
|
82
|
+
* Nested configurations override inherited settings
|
83
|
+
* Indifferent hash access, symbol, strings, case sensitivity optional ?
|
84
|
+
* Iterate over items hash - access to hash / mixin enumerable / delegation to hash ?
|
85
|
+
* Load configurations from a string or file at creation
|
86
|
+
* Load configurations from a string or file after creation / in DSL
|
87
|
+
* Configuration file load path - array of Dir.glob like file specs ?
|
88
|
+
* Load other formats ? - No need... DSL is just ruby, just do it natively.
|
89
|
+
* Blank slate for DSL ? - optional ?
|
90
|
+
* Use an existing configuration for defaults
|
91
|
+
* Global configuration - watch for collisions ?
|
92
|
+
* Consider issues around deferred interpolation / procs / lambdas etc...
|
88
93
|
|
89
94
|
## License
|
90
95
|
|
data/Rakefile
CHANGED
data/iqeo-conf.gemspec
CHANGED
@@ -9,8 +9,12 @@ Gem::Specification.new do |gem|
|
|
9
9
|
gem.homepage = "http://github.com/iqeo/iqeo-conf"
|
10
10
|
gem.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
11
11
|
gem.files = `git ls-files`.split("\n")
|
12
|
-
gem.test_files = `git ls-files -- {
|
12
|
+
gem.test_files = `git ls-files -- {spec}/*`.split("\n")
|
13
13
|
gem.name = "iqeo-conf"
|
14
14
|
gem.require_paths = ["lib"]
|
15
15
|
gem.version = Iqeo::Configuration::VERSION
|
16
|
+
|
17
|
+
gem.add_development_dependency "rspec", "~> 2.9.0"
|
18
|
+
gem.add_development_dependency "rake", "~> 0.9.2"
|
19
|
+
|
16
20
|
end
|
data/lib/iqeo/configuration.rb
CHANGED
@@ -1,12 +1,24 @@
|
|
1
1
|
|
2
2
|
require_relative "configuration/version"
|
3
3
|
|
4
|
+
# todo: inherited settings for nested configurations - POLS ?
|
5
|
+
# todo: load configurations from string & file
|
6
|
+
# todo: configuration file load path
|
7
|
+
# todo: iterate over items hash - access to hash / mixin enumerable / delegation to hash ?
|
8
|
+
# todo: indifferent hash access
|
9
|
+
# todo: use an existing configuration for defaults
|
10
|
+
# todo: global configuration - watch for collisions ?
|
11
|
+
# todo: deferred interpolation / procs / lambdas etc...
|
12
|
+
# todo: blank slate for DSL - optional ?
|
13
|
+
# todo: load other formats from string & file - YAML, XML?
|
14
|
+
|
4
15
|
module Iqeo
|
5
16
|
|
6
17
|
class Configuration
|
7
18
|
|
8
|
-
|
9
|
-
|
19
|
+
def self.version
|
20
|
+
VERSION
|
21
|
+
end
|
10
22
|
|
11
23
|
def initialize &block
|
12
24
|
@items = {}
|
@@ -19,16 +31,18 @@ module Iqeo
|
|
19
31
|
end
|
20
32
|
end
|
21
33
|
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
34
|
+
def method_missing name, *values
|
35
|
+
case name
|
36
|
+
when :[]= then return @items[values.shift] = values.size > 1 ? values : values.first
|
37
|
+
when :[] then return @items[values.shift]
|
38
|
+
else
|
39
|
+
name = name.to_s.chomp('=').to_sym
|
40
|
+
return @items[name] if values.empty?
|
41
|
+
return @items[name] = values if values.size > 1
|
42
|
+
return @items[name] = values.first
|
43
|
+
end
|
29
44
|
end
|
30
|
-
|
31
|
-
end
|
45
|
+
end
|
32
46
|
|
33
47
|
end
|
34
48
|
|
Binary file
|
Binary file
|
@@ -0,0 +1,280 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require 'iqeo/configuration'
|
3
|
+
|
4
|
+
include Iqeo
|
5
|
+
|
6
|
+
describe Configuration do
|
7
|
+
|
8
|
+
it 'reports the correct version' do
|
9
|
+
Configuration.version.should == Configuration::VERSION
|
10
|
+
end
|
11
|
+
|
12
|
+
context 'creation' do
|
13
|
+
|
14
|
+
it 'does not require a block' do
|
15
|
+
Configuration.new.should be_a Configuration
|
16
|
+
end
|
17
|
+
|
18
|
+
it 'accepts a block with arity 0' do
|
19
|
+
Configuration.new { }.should be_a Configuration
|
20
|
+
end
|
21
|
+
|
22
|
+
it 'instance_eval\'s block with arity 0' do
|
23
|
+
conf_eval = nil
|
24
|
+
conf_new = Configuration.new { conf_eval = self }
|
25
|
+
conf_new.should be conf_eval
|
26
|
+
end
|
27
|
+
|
28
|
+
it 'accepts a block with arity 1' do
|
29
|
+
Configuration.new { |arg| }.should be_a Configuration
|
30
|
+
end
|
31
|
+
|
32
|
+
it 'yields self to block with arity 1' do
|
33
|
+
conf_yielded = nil
|
34
|
+
conf_new = Configuration.new { |conf| conf_yielded = conf }
|
35
|
+
conf_new.should be conf_yielded
|
36
|
+
end
|
37
|
+
|
38
|
+
end
|
39
|
+
|
40
|
+
context 'settings retrieval' do
|
41
|
+
|
42
|
+
it 'returns nil for non-existent settings' do
|
43
|
+
conf = Configuration.new
|
44
|
+
conf.not_a_setting.should be_nil
|
45
|
+
end
|
46
|
+
|
47
|
+
end
|
48
|
+
|
49
|
+
context 'single value setting' do
|
50
|
+
|
51
|
+
it 'accepts simple values' do
|
52
|
+
conf = nil
|
53
|
+
expect do
|
54
|
+
conf = Configuration.new
|
55
|
+
conf.alpha 1
|
56
|
+
conf.bravo "two"
|
57
|
+
conf.charlie 3.0
|
58
|
+
conf.delta :four
|
59
|
+
end.to_not raise_error
|
60
|
+
conf.should_not be_nil
|
61
|
+
conf.alpha.should == 1 and conf.alpha.should be_a Fixnum
|
62
|
+
conf.bravo.should == "two" and conf.bravo.should be_a String
|
63
|
+
conf.charlie.should == 3.0 and conf.charlie.should be_a Float
|
64
|
+
conf.delta.should == :four and conf.delta.should be_a Symbol
|
65
|
+
end
|
66
|
+
|
67
|
+
it 'accepts complex values' do
|
68
|
+
conf = nil
|
69
|
+
expect do
|
70
|
+
conf = Configuration.new
|
71
|
+
conf.alpha = [ :a, :b, :c ]
|
72
|
+
conf.bravo = { :a => 1, :b => 2, :c => 3 }
|
73
|
+
end.to_not raise_error
|
74
|
+
conf.should_not be_nil
|
75
|
+
conf.alpha.should == [ :a, :b, :c] and conf.alpha.should be_an Array
|
76
|
+
conf.alpha.size.should == 3
|
77
|
+
conf.alpha[0].should == :a
|
78
|
+
conf.alpha[1].should == :b
|
79
|
+
conf.alpha[2].should == :c
|
80
|
+
conf.bravo.should == { :a => 1, :b => 2, :c => 3} and conf.bravo.should be_a Hash
|
81
|
+
conf.bravo.size.should == 3
|
82
|
+
conf.bravo[:a].should == 1
|
83
|
+
conf.bravo[:b].should == 2
|
84
|
+
conf.bravo[:c].should == 3
|
85
|
+
end
|
86
|
+
|
87
|
+
end
|
88
|
+
|
89
|
+
context 'multiple value setting' do
|
90
|
+
|
91
|
+
it 'accepts hash without brackets' do
|
92
|
+
conf = nil
|
93
|
+
expect do
|
94
|
+
conf = Configuration.new
|
95
|
+
conf.alpha :a => 1, :b => 2, :c => 3
|
96
|
+
end.to_not raise_error
|
97
|
+
conf.should_not be_nil
|
98
|
+
conf.alpha.should == { :a => 1, :b => 2, :c => 3} and conf.alpha.should be_a Hash
|
99
|
+
end
|
100
|
+
|
101
|
+
it 'treats multiple values as an array' do
|
102
|
+
conf = nil
|
103
|
+
expect do
|
104
|
+
conf = Configuration.new
|
105
|
+
conf.alpha :a, :b, :c
|
106
|
+
end.to_not raise_error
|
107
|
+
conf.should_not be_nil
|
108
|
+
conf.alpha.should == [ :a, :b, :c ] and conf.alpha.should be_an Array
|
109
|
+
end
|
110
|
+
|
111
|
+
it 'treats hash without brackets after multiple values as last element of array' do
|
112
|
+
conf = nil
|
113
|
+
expect do
|
114
|
+
conf = Configuration.new
|
115
|
+
conf.alpha 1, 2, 3, :a => 4, :b => 5, :c => 6
|
116
|
+
end.to_not raise_error
|
117
|
+
conf.should_not be_nil
|
118
|
+
conf.alpha.should == [ 1, 2, 3, { :a => 4, :b => 5, :c => 6} ] and conf.alpha.should be_a Array
|
119
|
+
end
|
120
|
+
|
121
|
+
end
|
122
|
+
|
123
|
+
context 'hash operators [] & []= access' do
|
124
|
+
|
125
|
+
it 'accepts symbol keys' do
|
126
|
+
conf = nil
|
127
|
+
expect do
|
128
|
+
conf = Configuration.new
|
129
|
+
conf[:alpha] = 1
|
130
|
+
end.to_not raise_error
|
131
|
+
conf[:alpha].should == 1
|
132
|
+
end
|
133
|
+
|
134
|
+
it 'accepts non-symbol (string) keys' do
|
135
|
+
conf = nil
|
136
|
+
expect do
|
137
|
+
conf = Configuration.new
|
138
|
+
conf['alpha'] = 1
|
139
|
+
end.to_not raise_error
|
140
|
+
conf.should_not be_nil
|
141
|
+
conf['alpha'].should == 1
|
142
|
+
end
|
143
|
+
|
144
|
+
end
|
145
|
+
|
146
|
+
context 'nested configuration' do
|
147
|
+
|
148
|
+
it 'is supported' do
|
149
|
+
conf = nil
|
150
|
+
expect do
|
151
|
+
conf = Configuration.new
|
152
|
+
conf.alpha Configuration.new
|
153
|
+
conf.alpha.bravo Configuration.new
|
154
|
+
conf.alpha.bravo.charlie true
|
155
|
+
end.to_not raise_error
|
156
|
+
conf.should_not be_nil
|
157
|
+
conf.alpha.should be_a Configuration
|
158
|
+
conf.alpha.bravo.should be_a Configuration
|
159
|
+
conf.alpha.bravo.charlie.should be_true
|
160
|
+
end
|
161
|
+
|
162
|
+
it 'inherits settings' do
|
163
|
+
pending 'todo'
|
164
|
+
end
|
165
|
+
|
166
|
+
it 'can override inherited settings' do
|
167
|
+
pending 'todo'
|
168
|
+
end
|
169
|
+
|
170
|
+
end
|
171
|
+
|
172
|
+
context 'yield DSL' do
|
173
|
+
|
174
|
+
it 'accepts settings without =' do
|
175
|
+
conf = nil
|
176
|
+
expect do
|
177
|
+
conf = Configuration.new do |c|
|
178
|
+
c.alpha :value
|
179
|
+
end
|
180
|
+
end.to_not raise_error
|
181
|
+
conf.should_not be_nil
|
182
|
+
conf.alpha.should == :value
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'accepts settings with =' do
|
186
|
+
conf = nil
|
187
|
+
expect do
|
188
|
+
conf = Configuration.new do |c|
|
189
|
+
c.alpha = :value
|
190
|
+
end
|
191
|
+
end.to_not raise_error
|
192
|
+
conf.should_not be_nil
|
193
|
+
conf.alpha.should == :value
|
194
|
+
end
|
195
|
+
|
196
|
+
it 'can refer to an existing setting' do
|
197
|
+
conf = nil
|
198
|
+
expect do
|
199
|
+
conf = Configuration.new do |c|
|
200
|
+
c.alpha = :value
|
201
|
+
c.bravo = c.alpha
|
202
|
+
c.charlie c.bravo
|
203
|
+
end
|
204
|
+
end.to_not raise_error
|
205
|
+
conf.should_not be_nil
|
206
|
+
conf.alpha.should == :value
|
207
|
+
conf.bravo.should == :value
|
208
|
+
conf.charlie.should == :value
|
209
|
+
end
|
210
|
+
|
211
|
+
it 'returns value when creating/changing a setting' do
|
212
|
+
conf = nil
|
213
|
+
expect do
|
214
|
+
conf = Configuration.new do |c|
|
215
|
+
c.bravo = c.alpha = :value
|
216
|
+
end
|
217
|
+
end.to_not raise_error
|
218
|
+
conf.alpha.should == :value
|
219
|
+
conf.bravo.should == :value
|
220
|
+
end
|
221
|
+
|
222
|
+
end
|
223
|
+
|
224
|
+
context 'instance_eval DSL' do
|
225
|
+
|
226
|
+
it 'accepts settings without =' do
|
227
|
+
conf = nil
|
228
|
+
expect do
|
229
|
+
conf = Configuration.new do
|
230
|
+
alpha :value
|
231
|
+
end
|
232
|
+
end.to_not raise_error
|
233
|
+
conf.should_not be_nil
|
234
|
+
conf.alpha.should == :value
|
235
|
+
end
|
236
|
+
|
237
|
+
it 'sets local variables with =' do
|
238
|
+
conf = alpha = nil
|
239
|
+
expect do
|
240
|
+
alpha = nil
|
241
|
+
conf = Configuration.new do
|
242
|
+
alpha = :value
|
243
|
+
bravo alpha
|
244
|
+
end
|
245
|
+
end.to_not raise_error
|
246
|
+
conf.should_not be_nil
|
247
|
+
conf.alpha.should be_nil
|
248
|
+
conf.bravo.should == :value
|
249
|
+
alpha.should == :value # local alpha set by matching variables
|
250
|
+
end
|
251
|
+
|
252
|
+
it 'can refer to an existing setting' do
|
253
|
+
conf = nil
|
254
|
+
expect do
|
255
|
+
conf = Configuration.new do |c|
|
256
|
+
c.alpha :value
|
257
|
+
c.bravo c.alpha
|
258
|
+
c.charlie c.bravo
|
259
|
+
end
|
260
|
+
end.to_not raise_error
|
261
|
+
conf.should_not be_nil
|
262
|
+
conf.alpha.should == :value
|
263
|
+
conf.bravo.should == :value
|
264
|
+
conf.charlie.should == :value
|
265
|
+
end
|
266
|
+
|
267
|
+
it 'returns value when creating/changing a setting' do
|
268
|
+
conf = nil
|
269
|
+
expect do
|
270
|
+
conf = Configuration.new do
|
271
|
+
bravo alpha :value
|
272
|
+
end
|
273
|
+
end.to_not raise_error
|
274
|
+
conf.alpha.should == :value
|
275
|
+
conf.bravo.should == :value
|
276
|
+
end
|
277
|
+
|
278
|
+
end
|
279
|
+
|
280
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,11 @@
|
|
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
|
+
RSpec.configure do |config|
|
8
|
+
config.treat_symbols_as_metadata_keys_with_true_values = true
|
9
|
+
config.run_all_when_everything_filtered = true
|
10
|
+
config.filter_run :focus
|
11
|
+
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.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,8 +9,40 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-04-
|
13
|
-
dependencies:
|
12
|
+
date: 2012-04-24 00:00:00.000000000 Z
|
13
|
+
dependencies:
|
14
|
+
- !ruby/object:Gem::Dependency
|
15
|
+
name: rspec
|
16
|
+
requirement: !ruby/object:Gem::Requirement
|
17
|
+
none: false
|
18
|
+
requirements:
|
19
|
+
- - ~>
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: 2.9.0
|
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: 2.9.0
|
30
|
+
- !ruby/object:Gem::Dependency
|
31
|
+
name: rake
|
32
|
+
requirement: !ruby/object:Gem::Requirement
|
33
|
+
none: false
|
34
|
+
requirements:
|
35
|
+
- - ~>
|
36
|
+
- !ruby/object:Gem::Version
|
37
|
+
version: 0.9.2
|
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: 0.9.2
|
14
46
|
description: A configuration DSL
|
15
47
|
email:
|
16
48
|
- gerard.fowley@iqeo.net
|
@@ -20,6 +52,7 @@ extra_rdoc_files: []
|
|
20
52
|
files:
|
21
53
|
- .bundle/config
|
22
54
|
- .gitignore
|
55
|
+
- .rspec
|
23
56
|
- .rvmrc
|
24
57
|
- Gemfile
|
25
58
|
- Gemfile.lock
|
@@ -29,7 +62,11 @@ files:
|
|
29
62
|
- iqeo-conf.gemspec
|
30
63
|
- lib/iqeo/configuration.rb
|
31
64
|
- lib/iqeo/configuration/version.rb
|
65
|
+
- pkg/iqeo-conf-0.0.1.gem
|
66
|
+
- pkg/iqeo-conf-0.0.2.gem
|
32
67
|
- scratch.txt
|
68
|
+
- spec/configuration_spec.rb
|
69
|
+
- spec/spec_helper.rb
|
33
70
|
homepage: http://github.com/iqeo/iqeo-conf
|
34
71
|
licenses: []
|
35
72
|
post_install_message:
|