collapsium-config 0.3.0 → 0.4.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +6 -6
- data/README.md +234 -21
- data/collapsium-config.gemspec +2 -2
- data/lib/collapsium-config/configuration.rb +32 -54
- data/lib/collapsium-config/support/values.rb +50 -0
- data/lib/collapsium-config/version.rb +1 -1
- data/spec/configuration_spec.rb +26 -0
- data/spec/data/include-array.yml +3 -0
- data/spec/data/include-multiple2.yml +3 -0
- data/spec/data/include-nested.yml +5 -0
- data/spec/support_values_spec.rb +37 -0
- metadata +15 -6
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 0a2e09619cf514355f44f452ca59fd28a7843346
|
4
|
+
data.tar.gz: efbe2423aa303a6fc3ec19d94ebe95a7064a3186
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 609a05eefe1d7a6db2a11787bdee3ae865b642b30295e00b4e3192452789fad9c664895c20c0945faa59ae1c1be8d7a8f3ebd02b7c97bda09547f5a8c142c7d7
|
7
|
+
data.tar.gz: adc2a47d375e899e828028ebc1fedf021aa78782f70d9d1c43f682102bdda1720297eab3b315be51aee9199e4fa68c7f88cb49f178f5f921f5af75e899841c7f
|
data/Gemfile.lock
CHANGED
@@ -1,8 +1,8 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
collapsium-config (0.
|
5
|
-
collapsium (~> 0.
|
4
|
+
collapsium-config (0.4.0)
|
5
|
+
collapsium (~> 0.6)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
@@ -10,7 +10,7 @@ GEM
|
|
10
10
|
ast (2.3.0)
|
11
11
|
codeclimate-test-reporter (0.6.0)
|
12
12
|
simplecov (>= 0.7.1, < 1.0.0)
|
13
|
-
collapsium (0.
|
13
|
+
collapsium (0.6.1)
|
14
14
|
diff-lcs (1.2.5)
|
15
15
|
docile (1.1.5)
|
16
16
|
json (2.0.2)
|
@@ -32,7 +32,7 @@ GEM
|
|
32
32
|
diff-lcs (>= 1.2.0, < 2.0)
|
33
33
|
rspec-support (~> 3.5.0)
|
34
34
|
rspec-support (3.5.0)
|
35
|
-
rubocop (0.
|
35
|
+
rubocop (0.45.0)
|
36
36
|
parser (>= 2.3.1.1, < 3.0)
|
37
37
|
powerpack (~> 0.1)
|
38
38
|
rainbow (>= 1.99.1, < 3.0)
|
@@ -56,9 +56,9 @@ DEPENDENCIES
|
|
56
56
|
collapsium-config!
|
57
57
|
rake (~> 11.3)
|
58
58
|
rspec (~> 3.5)
|
59
|
-
rubocop (~> 0.
|
59
|
+
rubocop (~> 0.45)
|
60
60
|
simplecov (~> 0.12)
|
61
61
|
yard (~> 0.9)
|
62
62
|
|
63
63
|
BUNDLED WITH
|
64
|
-
1.
|
64
|
+
1.13.6
|
data/README.md
CHANGED
@@ -17,12 +17,14 @@ various configuration sources into one configuration object.
|
|
17
17
|
- Given a main configuration file `foo.yml` to load, also loads `foo-local.yml`
|
18
18
|
if that exists, and merges it's contents recursively into the main
|
19
19
|
configuration.
|
20
|
+
- Pathed access to configuration variables.
|
20
21
|
- Using the special `extends` configuration key, allows a configuration Hash
|
21
22
|
to include all values from other configuration Hash(es).
|
22
23
|
- Using the special, top-level `include` configuration key, allows a
|
23
24
|
configuration file to be split into multiple included files.
|
24
25
|
- As of `v0.2`, configuration files are [ERB templates](http://ruby-doc.org/stdlib-2.3.1/libdoc/erb/rdoc/ERB.html).
|
25
26
|
Do your templating stuff as you'd usually do it.
|
27
|
+
- Allows overriding of configuration values from the environment.
|
26
28
|
|
27
29
|
# Basic Usage
|
28
30
|
|
@@ -38,7 +40,9 @@ puts config["foo"] # loaded automatically from config.yml
|
|
38
40
|
|
39
41
|
# Advanced Usage
|
40
42
|
|
41
|
-
## Configuration File
|
43
|
+
## Configuration File Management
|
44
|
+
|
45
|
+
### Configuration File Location
|
42
46
|
|
43
47
|
The friendly neighbour to the `#config` function introduced in the basic
|
44
48
|
usage section above is the `#config_file` accessor. Its value will default
|
@@ -49,7 +53,7 @@ config_file = 'foo.yaml'
|
|
49
53
|
puts config["foo"] # loaded automatically from foo.yaml
|
50
54
|
```
|
51
55
|
|
52
|
-
|
56
|
+
### Loading Configuration Files
|
53
57
|
|
54
58
|
All that `#config` and `#config_file` do is wrap `#load_config` such that
|
55
59
|
configuration is loaded only once. You can load configuration files manually,
|
@@ -59,33 +63,66 @@ too:
|
|
59
63
|
my_config = Collapsium::Config::Configuration.load_config('filename.yaml')
|
60
64
|
```
|
61
65
|
|
62
|
-
|
66
|
+
### Array Files
|
67
|
+
|
68
|
+
Configuration files can also contain Arrays at the top level. While that may
|
69
|
+
make some sense at times, it does not make for good naming schemes and creates
|
70
|
+
problems elsewhere.
|
63
71
|
|
64
|
-
|
72
|
+
Therefore, if your file contains an Array at the top level, the class wraps it
|
73
|
+
into a Hash with a `config` key containing the Array:
|
65
74
|
|
66
75
|
```yaml
|
67
|
-
|
68
|
-
|
76
|
+
- foo
|
77
|
+
- bar
|
78
|
+
```
|
69
79
|
|
70
|
-
|
71
|
-
|
72
|
-
|
80
|
+
```ruby
|
81
|
+
config["config"][0] # => "foo"
|
82
|
+
config["config"][1] # => "bar"
|
73
83
|
```
|
74
84
|
|
75
|
-
|
76
|
-
the value at path `.base` into the value at path `.derived`. Additionally,
|
77
|
-
`.derived` will gain a new key `base` which is an Array containing all the
|
78
|
-
bases merged into the value.
|
85
|
+
### File Formats
|
79
86
|
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
+
The gem supports loading [YAML](http://yaml.org/) and [JSON](http://www.json.org/)
|
88
|
+
configuration files. Both formats can be mixed in the various mechanisms described
|
89
|
+
below.
|
90
|
+
|
91
|
+
### Local Configuration Overrides
|
92
|
+
|
93
|
+
For the example file of `config/config.yml`, if a file with the same path and
|
94
|
+
name, and the name postfix `-local` exists (i.e. `config/config-local.yml`), that
|
95
|
+
file will also be loaded. It's keys will be recursively added to the keys from the
|
96
|
+
main configuration file, overwriting only leaves, not entire hashes.
|
97
|
+
|
98
|
+
Example:
|
99
|
+
|
100
|
+
```yaml
|
101
|
+
# config/config.yml
|
102
|
+
---
|
103
|
+
foo:
|
104
|
+
bar: 42
|
105
|
+
baz: quux
|
106
|
+
|
107
|
+
# config/config-local.yml
|
108
|
+
---
|
109
|
+
something: else
|
110
|
+
foo:
|
111
|
+
baz: override
|
112
|
+
|
113
|
+
# result
|
114
|
+
---
|
115
|
+
something: else
|
116
|
+
foo:
|
117
|
+
bar: 42
|
118
|
+
baz: override
|
119
|
+
```
|
120
|
+
|
121
|
+
### Templating
|
87
122
|
|
88
|
-
|
123
|
+
Configuration files aren't quite static entities even taking merging of local
|
124
|
+
overrides into account. They can further be generated at load time by
|
125
|
+
templating, extension and including.
|
89
126
|
|
90
127
|
ERB templating in configuration files works out-of-the-box, but one of the
|
91
128
|
more powerful features is of course to substitute some values in the template
|
@@ -104,3 +141,179 @@ not to its individual keys:
|
|
104
141
|
<%= data[:some_key] %> # correct usage
|
105
142
|
<%= some_key %> # incorrect usage
|
106
143
|
```
|
144
|
+
|
145
|
+
But even without explicit passing of a data hash, you can use templating to
|
146
|
+
e.g. include environment variables:
|
147
|
+
|
148
|
+
```erb
|
149
|
+
foo: <%= ENV['MYVAR'] %>
|
150
|
+
```
|
151
|
+
|
152
|
+
Note, though, that this might interact unexpectedly with the environment
|
153
|
+
override feature described later.
|
154
|
+
|
155
|
+
|
156
|
+
### Extension
|
157
|
+
|
158
|
+
An additional feature is that you can extend individual hashes with values from
|
159
|
+
other hashes.
|
160
|
+
|
161
|
+
```yaml
|
162
|
+
---
|
163
|
+
root:
|
164
|
+
foo: bar
|
165
|
+
derived:
|
166
|
+
baz: quux
|
167
|
+
extends: root
|
168
|
+
```
|
169
|
+
|
170
|
+
This results in:
|
171
|
+
|
172
|
+
```yaml
|
173
|
+
---
|
174
|
+
root:
|
175
|
+
foo: bar
|
176
|
+
derived:
|
177
|
+
baz: quux
|
178
|
+
foo: bar
|
179
|
+
base: root
|
180
|
+
```
|
181
|
+
|
182
|
+
The special `extends` keyword is interpreted to merge all values from
|
183
|
+
the value at path `.root` into the value at path `.derived`. Additionally,
|
184
|
+
`.derived` will gain a new key `base` which is an Array containing all the
|
185
|
+
bases merged into the value.
|
186
|
+
|
187
|
+
**Notes:**
|
188
|
+
|
189
|
+
- Absolute paths are preferred for values of `extends`.
|
190
|
+
- Relative paths for values of `extends` are looked up in the parent of the
|
191
|
+
value that contains the `extends` keyword, i.e. the root in the example
|
192
|
+
above. So in this minimal example, specifying `.base` and `base` is
|
193
|
+
equivalent.
|
194
|
+
- You can specify a comma-separated list of bases in the `extends` keyword.
|
195
|
+
Latter paths overwrite values in earlier paths.
|
196
|
+
- You can also specify an Array of paths, with the same effect.
|
197
|
+
- This feature means that `extends` and `base` are reserved configuration keys!
|
198
|
+
- Multiple levels of extension are supported.
|
199
|
+
|
200
|
+
### Includes
|
201
|
+
|
202
|
+
Includes work just as you might expect: if you specify a key `include` anywhere,
|
203
|
+
the value will be interpreted as a file system path to another configuration file.
|
204
|
+
That other file will be loaded, and the parent of the `include` statement will
|
205
|
+
gain all the values from the other configuration file.
|
206
|
+
|
207
|
+
Example:
|
208
|
+
|
209
|
+
```yaml
|
210
|
+
# config/main.yml
|
211
|
+
include: config/first.yml
|
212
|
+
foo:
|
213
|
+
bar: 42
|
214
|
+
include: config/second.yml
|
215
|
+
```
|
216
|
+
|
217
|
+
```yaml
|
218
|
+
# config/first.yml
|
219
|
+
baz: quux
|
220
|
+
```
|
221
|
+
|
222
|
+
```yaml
|
223
|
+
# config/second.yml
|
224
|
+
- 123
|
225
|
+
- 456
|
226
|
+
```
|
227
|
+
|
228
|
+
Will result in:
|
229
|
+
|
230
|
+
```yaml
|
231
|
+
# final YAML
|
232
|
+
baz: quux
|
233
|
+
foo:
|
234
|
+
bar: 42
|
235
|
+
data:
|
236
|
+
- 123
|
237
|
+
- 456
|
238
|
+
```
|
239
|
+
|
240
|
+
**Notes:**
|
241
|
+
|
242
|
+
- If your loaded configuration file contains an Array at the top level, then
|
243
|
+
a new key `config` will be added (see Array Files above)
|
244
|
+
- You can specify a comma-separated list of paths in the `include` keyword.
|
245
|
+
Latter paths overwrite values in earlier paths.
|
246
|
+
- You can also specify an Array of paths, with the same effect.
|
247
|
+
- This means that `include` is a reserved configuration key.
|
248
|
+
|
249
|
+
## Configuration Access
|
250
|
+
|
251
|
+
### Pathed Access
|
252
|
+
|
253
|
+
Thanks to [collapsium](https://github.com/jfinkhaeuser/collapsium)'s `UberHash`,
|
254
|
+
configuration values can be accessed more easily than in a regular nested
|
255
|
+
structure. Take the following configuration as an example:
|
256
|
+
|
257
|
+
```yaml
|
258
|
+
---
|
259
|
+
foo:
|
260
|
+
bar:
|
261
|
+
baz: 42
|
262
|
+
quux:
|
263
|
+
- 123
|
264
|
+
- "asdf"
|
265
|
+
```
|
266
|
+
|
267
|
+
Then, the following are equivalent:
|
268
|
+
|
269
|
+
```ruby
|
270
|
+
config["foo"]["bar"]["baz"]
|
271
|
+
config["foo.bar.baz"]
|
272
|
+
config[".foo.bar.baz"]
|
273
|
+
config["foo.bar"]["baz"]
|
274
|
+
config["foo"]["bar.baz"]
|
275
|
+
```
|
276
|
+
|
277
|
+
The major benefit is that if *any* of the path components does not exist, nil is
|
278
|
+
returned (and the behaviour is equivalent to other access methods such as
|
279
|
+
`:fetch`, etc.)
|
280
|
+
|
281
|
+
Similarly you can use this type of access for writing: `config['baz.quux'] = 42`
|
282
|
+
will create both the `baz` hash, and it's child the `quux` key.
|
283
|
+
|
284
|
+
## Environment Override
|
285
|
+
|
286
|
+
Given a configuration path, any environment variable with the same name (change
|
287
|
+
path to upper case letters and replace `.` with `_`, e.g. `foo.bar` becomes
|
288
|
+
`FOO_BAR`) overrides the values in the configuration file.
|
289
|
+
|
290
|
+
```ruby
|
291
|
+
# Called with FOO_BAR=42
|
292
|
+
config["foo.bar"] # => 42
|
293
|
+
```
|
294
|
+
|
295
|
+
If the environment variable is parseable as JSON, then that parsed JSON will
|
296
|
+
**replace** the original configuration path (i.e. it will not be merged).
|
297
|
+
|
298
|
+
```ruby
|
299
|
+
# Called with FOO_BAR='{ "baz": 42 }'
|
300
|
+
config["foo.bar.baz"] # => 42
|
301
|
+
```
|
302
|
+
|
303
|
+
|
304
|
+
## A Note on Priorities
|
305
|
+
|
306
|
+
A lot of the features above interact with each other. For example, environment
|
307
|
+
override still respects pathed access. In other cases, things are not quite
|
308
|
+
so clear, so let's give you a rough idea on priorities in the code:
|
309
|
+
|
310
|
+
1. Templating happens when files are loaded, and generates the most basic data
|
311
|
+
the gem works with.
|
312
|
+
1. Configuration file merging happens next, i.e. `config.yml` and `config-local.yml`
|
313
|
+
are merged into one data structure.
|
314
|
+
1. Next up is handling of `include` directives.
|
315
|
+
1. After that, `extends` is resolved - that is, `extends` works on paths that
|
316
|
+
only exists after any of the above steps created them. This step finishes the
|
317
|
+
configuration loading process.
|
318
|
+
1. Finally, environment override works whenever a value is *accessed*, meaning
|
319
|
+
if the environment changes, so does the configuration value.
|
data/collapsium-config.gemspec
CHANGED
@@ -38,13 +38,13 @@ Gem::Specification.new do |spec|
|
|
38
38
|
spec.required_ruby_version = '>= 2.0'
|
39
39
|
|
40
40
|
spec.add_development_dependency "bundler", "~> 1.12"
|
41
|
-
spec.add_development_dependency "rubocop", "~> 0.
|
41
|
+
spec.add_development_dependency "rubocop", "~> 0.45"
|
42
42
|
spec.add_development_dependency "rake", "~> 11.3"
|
43
43
|
spec.add_development_dependency "rspec", "~> 3.5"
|
44
44
|
spec.add_development_dependency "simplecov", "~> 0.12"
|
45
45
|
spec.add_development_dependency "yard", "~> 0.9"
|
46
46
|
|
47
|
-
spec.add_dependency 'collapsium', '~> 0.
|
47
|
+
spec.add_dependency 'collapsium', '~> 0.6'
|
48
48
|
end
|
49
49
|
# rubocop:enable Metrics/BlockLength
|
50
50
|
# rubocop:enable Style/SpaceAroundOperators
|
@@ -9,6 +9,8 @@
|
|
9
9
|
|
10
10
|
require 'collapsium'
|
11
11
|
|
12
|
+
require 'collapsium-config/support/values'
|
13
|
+
|
12
14
|
module Collapsium
|
13
15
|
module Config
|
14
16
|
##
|
@@ -40,6 +42,7 @@ module Collapsium
|
|
40
42
|
# result may be unexpected.
|
41
43
|
class Configuration < ::Collapsium::UberHash
|
42
44
|
include ::Collapsium::EnvironmentOverride
|
45
|
+
include ::Collapsium::Config::Support::Values
|
43
46
|
|
44
47
|
# @api private
|
45
48
|
# Very simple YAML parser
|
@@ -70,6 +73,8 @@ module Collapsium
|
|
70
73
|
end
|
71
74
|
|
72
75
|
class << self
|
76
|
+
include ::Collapsium::Config::Support::Values
|
77
|
+
|
73
78
|
# @api private
|
74
79
|
# Mapping of file name extensions to parser types.
|
75
80
|
FILE_TO_PARSER = {
|
@@ -109,7 +114,7 @@ module Collapsium
|
|
109
114
|
config.recursive_merge!(local_config)
|
110
115
|
|
111
116
|
# Resolve includes
|
112
|
-
config = resolve_includes(base, config, options
|
117
|
+
config = resolve_includes(base, config, options)
|
113
118
|
|
114
119
|
# Create config from the result
|
115
120
|
cfg = Configuration.new(config)
|
@@ -183,63 +188,37 @@ module Collapsium
|
|
183
188
|
return data
|
184
189
|
end
|
185
190
|
|
186
|
-
def resolve_includes(base, config,
|
187
|
-
|
188
|
-
|
189
|
-
|
190
|
-
|
191
|
-
# Figure out includes
|
192
|
-
outer_inc = extract_includes(config)
|
193
|
-
if not outer_inc.empty?
|
194
|
-
includes = outer_inc
|
195
|
-
end
|
196
|
-
|
197
|
-
to_process = includes - processed
|
198
|
-
|
199
|
-
# Stop resolving when all includes have been processed
|
200
|
-
if to_process.empty?
|
201
|
-
break
|
202
|
-
end
|
203
|
-
|
204
|
-
# Load and merge the include files
|
205
|
-
to_process.each do |filename|
|
206
|
-
incfile = Pathname.new(base.dirname)
|
207
|
-
incfile = incfile.join(filename)
|
208
|
-
|
209
|
-
# Just try to open it, if that errors out that's ok.
|
210
|
-
file = incfile.open
|
211
|
-
contents = file.read
|
212
|
-
|
213
|
-
parsed = parse(incfile.extname, contents, template_data)
|
214
|
-
|
215
|
-
# Extract and merge includes
|
216
|
-
inner_inc = extract_includes(parsed)
|
217
|
-
includes += inner_inc
|
218
|
-
|
219
|
-
# Merge the rest
|
220
|
-
config.recursive_merge!(hashify(parsed))
|
191
|
+
def resolve_includes(base, config, options)
|
192
|
+
# Only process Hashes
|
193
|
+
if not config.is_a? Hash
|
194
|
+
return config
|
195
|
+
end
|
221
196
|
|
222
|
-
|
197
|
+
# Figure out includes. We have to recursively fetch the string and
|
198
|
+
# the symbol keys, and process includes where we find them.
|
199
|
+
["include", :include].each do |key|
|
200
|
+
config.recursive_fetch_all(key) do |parent, value, _|
|
201
|
+
# The value contains the includes
|
202
|
+
includes = array_value(value)
|
203
|
+
parent.delete(key)
|
204
|
+
|
205
|
+
# Now merge all includes into the parent
|
206
|
+
includes.each do |filename|
|
207
|
+
# Load included file
|
208
|
+
incfile = Pathname.new(base.dirname)
|
209
|
+
incfile = incfile.join(filename)
|
210
|
+
|
211
|
+
# Due to the way recursive_fetch works, we may get bad
|
212
|
+
included = Configuration.load_config(incfile, options)
|
213
|
+
|
214
|
+
# Merge included
|
215
|
+
parent.recursive_merge!(hashify(included), true)
|
216
|
+
end
|
223
217
|
end
|
224
218
|
end
|
225
219
|
|
226
220
|
return config
|
227
221
|
end
|
228
|
-
|
229
|
-
def extract_includes(config)
|
230
|
-
# Figure out includes
|
231
|
-
includes = config.fetch("include", [])
|
232
|
-
config.delete("include")
|
233
|
-
includes = config.fetch(:include, includes)
|
234
|
-
config.delete(:include)
|
235
|
-
|
236
|
-
# We might have a simple/string include
|
237
|
-
if not includes.is_a? Array
|
238
|
-
includes = [includes]
|
239
|
-
end
|
240
|
-
|
241
|
-
return includes
|
242
|
-
end
|
243
222
|
end # class << self
|
244
223
|
|
245
224
|
##
|
@@ -311,8 +290,7 @@ module Collapsium
|
|
311
290
|
end
|
312
291
|
|
313
292
|
# Now to resolve the path to the base and remove the "extends" keyword.
|
314
|
-
base_paths = value["extends"]
|
315
|
-
base_paths = base_paths.split(/,/).map(&:strip)
|
293
|
+
base_paths = array_value(value["extends"])
|
316
294
|
bases = {}
|
317
295
|
base_paths.each do |base_path|
|
318
296
|
if not base_path.start_with?(separator)
|
@@ -0,0 +1,50 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
#
|
3
|
+
# collapsium-config
|
4
|
+
# https://github.com/jfinkhaeuser/collapsium-config
|
5
|
+
#
|
6
|
+
# Copyright (c) 2016 Jens Finkhaeuser and other collapsium-config contributors.
|
7
|
+
# All rights reserved.
|
8
|
+
#
|
9
|
+
|
10
|
+
require 'collapsium'
|
11
|
+
|
12
|
+
module Collapsium
|
13
|
+
module Config
|
14
|
+
##
|
15
|
+
# Contains support code
|
16
|
+
module Support
|
17
|
+
##
|
18
|
+
# Contains helper functions for parsing configuration values.
|
19
|
+
module Values
|
20
|
+
|
21
|
+
##
|
22
|
+
# Given the value, turn it into an Array:
|
23
|
+
# - comma-separated strings are split
|
24
|
+
# - other single values are wrapped into an Array
|
25
|
+
def array_value(value)
|
26
|
+
# Split comma-separated strings.
|
27
|
+
if value.respond_to? :split
|
28
|
+
value = value.split(/,/)
|
29
|
+
end
|
30
|
+
|
31
|
+
# If the value is an Array, we strip its string elements.
|
32
|
+
if value.is_a? Array
|
33
|
+
value = value.map do |v|
|
34
|
+
if v.respond_to? :strip
|
35
|
+
next v.strip
|
36
|
+
end
|
37
|
+
next v
|
38
|
+
end
|
39
|
+
else
|
40
|
+
# Otherwise turn the value into an Array if it's a single
|
41
|
+
# value.
|
42
|
+
value = [value]
|
43
|
+
end
|
44
|
+
|
45
|
+
return value
|
46
|
+
end
|
47
|
+
end # module Values
|
48
|
+
end # module Support
|
49
|
+
end # module Config
|
50
|
+
end # module Collapsium
|
data/spec/configuration_spec.rb
CHANGED
@@ -180,6 +180,15 @@ describe Collapsium::Config::Configuration do
|
|
180
180
|
expect(cfg["baz"]).to eql 'test'
|
181
181
|
end
|
182
182
|
|
183
|
+
it "can include multiple files from a comma-separated list" do
|
184
|
+
config = File.join(@data_path, 'include-multiple2.yml')
|
185
|
+
cfg = Collapsium::Config::Configuration.load_config(config)
|
186
|
+
|
187
|
+
expect(cfg["foo"]).to eql 42
|
188
|
+
expect(cfg["bar"]).to eql 'quux'
|
189
|
+
expect(cfg["baz"]).to eql 'test'
|
190
|
+
end
|
191
|
+
|
183
192
|
it "can resolve includes recursively" do
|
184
193
|
config = File.join(@data_path, 'include-recursive.yml')
|
185
194
|
cfg = Collapsium::Config::Configuration.load_config(config)
|
@@ -198,6 +207,23 @@ describe Collapsium::Config::Configuration do
|
|
198
207
|
expect(cfg["bar.foo"]).to eql 'something'
|
199
208
|
expect(cfg["bar.baz"]).to eql 42
|
200
209
|
end
|
210
|
+
|
211
|
+
it "can include array configuration files" do
|
212
|
+
config = File.join(@data_path, 'include-array.yml')
|
213
|
+
cfg = Collapsium::Config::Configuration.load_config(config)
|
214
|
+
|
215
|
+
expect(cfg["quux"]).to eql "baz"
|
216
|
+
expect(cfg["config"]).to eql %w(foo bar)
|
217
|
+
end
|
218
|
+
|
219
|
+
it "works in nested structures" do
|
220
|
+
config = File.join(@data_path, 'include-nested.yml')
|
221
|
+
cfg = Collapsium::Config::Configuration.load_config(config)
|
222
|
+
|
223
|
+
expect(cfg["foo"]).to eql "bar"
|
224
|
+
expect(cfg["baz.quux"]).to eql "baz" # Overridden from include!
|
225
|
+
expect(cfg["baz.config"]).to eql %w(foo bar)
|
226
|
+
end
|
201
227
|
end
|
202
228
|
|
203
229
|
describe "behaves like a UberHash" do
|
@@ -0,0 +1,37 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
require_relative '../lib/collapsium-config/support/values'
|
3
|
+
|
4
|
+
describe Collapsium::Config::Support::Values do
|
5
|
+
let(:tester) { Class.new { extend Collapsium::Config::Support::Values } }
|
6
|
+
|
7
|
+
context "#array_value" do
|
8
|
+
it "splits a comma separated string" do
|
9
|
+
expect(tester.array_value("foo,bar")).to eql %w(foo bar)
|
10
|
+
end
|
11
|
+
|
12
|
+
it "strips spaces from comma separated strings" do
|
13
|
+
expect(tester.array_value(" foo , bar ")).to eql %w(foo bar)
|
14
|
+
end
|
15
|
+
|
16
|
+
it "turns single strings into an array" do
|
17
|
+
expect(tester.array_value("foo")).to eql %w(foo)
|
18
|
+
end
|
19
|
+
|
20
|
+
it "strips spaces from single strings" do
|
21
|
+
expect(tester.array_value(" foo ")).to eql %w(foo)
|
22
|
+
end
|
23
|
+
|
24
|
+
it "strips array elements" do
|
25
|
+
expect(tester.array_value(['foo ', ' bar'])).to eql %w(foo bar)
|
26
|
+
end
|
27
|
+
|
28
|
+
it "wraps other values into arrays" do
|
29
|
+
expect(tester.array_value({})).to eql [{}]
|
30
|
+
expect(tester.array_value(42)).to eql [42]
|
31
|
+
end
|
32
|
+
|
33
|
+
it "handles mixed arrays well" do
|
34
|
+
expect(tester.array_value([42, 'foo'])).to eql [42, 'foo']
|
35
|
+
end
|
36
|
+
end
|
37
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: collapsium-config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.4.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Jens Finkhaeuser
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-
|
11
|
+
date: 2016-11-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -30,14 +30,14 @@ dependencies:
|
|
30
30
|
requirements:
|
31
31
|
- - "~>"
|
32
32
|
- !ruby/object:Gem::Version
|
33
|
-
version: '0.
|
33
|
+
version: '0.45'
|
34
34
|
type: :development
|
35
35
|
prerelease: false
|
36
36
|
version_requirements: !ruby/object:Gem::Requirement
|
37
37
|
requirements:
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
|
-
version: '0.
|
40
|
+
version: '0.45'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
42
|
name: rake
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -100,14 +100,14 @@ dependencies:
|
|
100
100
|
requirements:
|
101
101
|
- - "~>"
|
102
102
|
- !ruby/object:Gem::Version
|
103
|
-
version: '0.
|
103
|
+
version: '0.6'
|
104
104
|
type: :runtime
|
105
105
|
prerelease: false
|
106
106
|
version_requirements: !ruby/object:Gem::Requirement
|
107
107
|
requirements:
|
108
108
|
- - "~>"
|
109
109
|
- !ruby/object:Gem::Version
|
110
|
-
version: '0.
|
110
|
+
version: '0.6'
|
111
111
|
description: "\n Using collapsium's UberHash class for easy access to configuration
|
112
112
|
values,\n this gem reads and merges various configuration sources into one\n
|
113
113
|
\ configuration object.\n "
|
@@ -130,6 +130,7 @@ files:
|
|
130
130
|
- collapsium-config.gemspec
|
131
131
|
- lib/collapsium-config.rb
|
132
132
|
- lib/collapsium-config/configuration.rb
|
133
|
+
- lib/collapsium-config/support/values.rb
|
133
134
|
- lib/collapsium-config/version.rb
|
134
135
|
- spec/configuration_spec.rb
|
135
136
|
- spec/data/array.yaml
|
@@ -138,8 +139,11 @@ files:
|
|
138
139
|
- spec/data/extend.yml
|
139
140
|
- spec/data/global.yml
|
140
141
|
- spec/data/hash.yml
|
142
|
+
- spec/data/include-array.yml
|
141
143
|
- spec/data/include-extend.yml
|
142
144
|
- spec/data/include-multiple.yml
|
145
|
+
- spec/data/include-multiple2.yml
|
146
|
+
- spec/data/include-nested.yml
|
143
147
|
- spec/data/include-recursive.yml
|
144
148
|
- spec/data/include-simple.yml
|
145
149
|
- spec/data/include1.yml
|
@@ -156,6 +160,7 @@ files:
|
|
156
160
|
- spec/data/test.json
|
157
161
|
- spec/module_spec.rb
|
158
162
|
- spec/spec_helper.rb
|
163
|
+
- spec/support_values_spec.rb
|
159
164
|
homepage: https://github.com/jfinkhaeuser/collapsium-config
|
160
165
|
licenses:
|
161
166
|
- MITNFA
|
@@ -188,8 +193,11 @@ test_files:
|
|
188
193
|
- spec/data/extend.yml
|
189
194
|
- spec/data/global.yml
|
190
195
|
- spec/data/hash.yml
|
196
|
+
- spec/data/include-array.yml
|
191
197
|
- spec/data/include-extend.yml
|
192
198
|
- spec/data/include-multiple.yml
|
199
|
+
- spec/data/include-multiple2.yml
|
200
|
+
- spec/data/include-nested.yml
|
193
201
|
- spec/data/include-recursive.yml
|
194
202
|
- spec/data/include-simple.yml
|
195
203
|
- spec/data/include1.yml
|
@@ -206,3 +214,4 @@ test_files:
|
|
206
214
|
- spec/data/test.json
|
207
215
|
- spec/module_spec.rb
|
208
216
|
- spec/spec_helper.rb
|
217
|
+
- spec/support_values_spec.rb
|