collapsium-config 0.4.0 → 0.4.1

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 0a2e09619cf514355f44f452ca59fd28a7843346
4
- data.tar.gz: efbe2423aa303a6fc3ec19d94ebe95a7064a3186
3
+ metadata.gz: 2f73bde177ede4ff9e18afef840427c05f50f512
4
+ data.tar.gz: bbc9fc38003b7353d28137deeaf719990eb8c53a
5
5
  SHA512:
6
- metadata.gz: 609a05eefe1d7a6db2a11787bdee3ae865b642b30295e00b4e3192452789fad9c664895c20c0945faa59ae1c1be8d7a8f3ebd02b7c97bda09547f5a8c142c7d7
7
- data.tar.gz: adc2a47d375e899e828028ebc1fedf021aa78782f70d9d1c43f682102bdda1720297eab3b315be51aee9199e4fa68c7f88cb49f178f5f921f5af75e899841c7f
6
+ metadata.gz: 5173c739f0c6c9a368238791f642850be2991d4ef74b78eec967a835fd33027b67842d6897940b5f7f3961d37045b88a9fcc0e3c3cd3f087ff321a54e236c4c7
7
+ data.tar.gz: 94f98c030682cce256543d6dc93647afec109edd5db1868437bfe7a13958d3a547d266831b87fd521a9c48e3f37d2199045e8ae635913ba682077b9fe8cb6a6e
data/.travis.yml CHANGED
@@ -3,6 +3,9 @@ rvm:
3
3
  - 2.0
4
4
  - 2.1
5
5
  - 2.2
6
+ script:
7
+ - bundle exec rake
8
+ - bundle exec codeclimate-test-reporter
6
9
  addons:
7
10
  code_climate:
8
11
  repo_token: 3cca4d10a51839bc5d115d41a0c12b98cbdb27a21e9c86544324fa028b799b84
data/Gemfile.lock CHANGED
@@ -1,15 +1,14 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- collapsium-config (0.4.0)
4
+ collapsium-config (0.4.1)
5
5
  collapsium (~> 0.6)
6
6
 
7
7
  GEM
8
8
  remote: https://rubygems.org/
9
9
  specs:
10
10
  ast (2.3.0)
11
- codeclimate-test-reporter (0.6.0)
12
- simplecov (>= 0.7.1, < 1.0.0)
11
+ codeclimate-test-reporter (1.0.1)
13
12
  collapsium (0.6.1)
14
13
  diff-lcs (1.2.5)
15
14
  docile (1.1.5)
data/README.md CHANGED
@@ -10,20 +10,12 @@ various configuration sources into one configuration object.
10
10
  [![Code Climate](https://codeclimate.com/github/jfinkhaeuser/collapsium-config/badges/gpa.svg)](https://codeclimate.com/github/jfinkhaeuser/collapsium-config)
11
11
  [![Test Coverage](https://codeclimate.com/github/jfinkhaeuser/collapsium-config/badges/coverage.svg)](https://codeclimate.com/github/jfinkhaeuser/collapsium-config/coverage)
12
12
 
13
- # Functionality
13
+ # Summary
14
14
 
15
15
  - Supports [JSON](http://www.json.org/) and [YAML](http://yaml.org/) file
16
16
  formats.
17
- - Given a main configuration file `foo.yml` to load, also loads `foo-local.yml`
18
- if that exists, and merges it's contents recursively into the main
19
- configuration.
17
+ - Generates configuration files from ERB templates, includes, local override files and an extension mechanism.
20
18
  - Pathed access to configuration variables.
21
- - Using the special `extends` configuration key, allows a configuration Hash
22
- to include all values from other configuration Hash(es).
23
- - Using the special, top-level `include` configuration key, allows a
24
- configuration file to be split into multiple included files.
25
- - As of `v0.2`, configuration files are [ERB templates](http://ruby-doc.org/stdlib-2.3.1/libdoc/erb/rdoc/ERB.html).
26
- Do your templating stuff as you'd usually do it.
27
19
  - Allows overriding of configuration values from the environment.
28
20
 
29
21
  # Basic Usage
@@ -196,6 +188,10 @@ bases merged into the value.
196
188
  - You can also specify an Array of paths, with the same effect.
197
189
  - This feature means that `extends` and `base` are reserved configuration keys!
198
190
  - Multiple levels of extension are supported.
191
+ - The order of items in `base` is deterministic:
192
+ 1. Items are added in the order in which they appear in `extends`, but...
193
+ 1. ... after each item, the items it itself extends are added before the next
194
+ item is processed.
199
195
 
200
196
  ### Includes
201
197
 
@@ -191,7 +191,9 @@ module Collapsium
191
191
  def resolve_includes(base, config, options)
192
192
  # Only process Hashes
193
193
  if not config.is_a? Hash
194
+ # :nocov:
194
195
  return config
196
+ # :nocov:
195
197
  end
196
198
 
197
199
  # Figure out includes. We have to recursively fetch the string and
@@ -290,11 +292,20 @@ module Collapsium
290
292
  end
291
293
 
292
294
  # Now to resolve the path to the base and remove the "extends" keyword.
295
+ bases = fetch_base_values(root, parent_path(path), value)
296
+
297
+ # Merge the bases
298
+ merge_base_values(root, value, bases)
299
+
300
+ # And we're done, set the value to what was being merged.
301
+ root[path] = value
302
+ end
303
+
304
+ def fetch_base_values(root, parent, value)
293
305
  base_paths = array_value(value["extends"])
294
- bases = {}
306
+ bases = []
295
307
  base_paths.each do |base_path|
296
308
  if not base_path.start_with?(separator)
297
- parent = parent_path(path)
298
309
  base_path = "#{parent}#{separator}#{base_path}"
299
310
  end
300
311
  base_path = normalize_path(base_path)
@@ -307,7 +318,7 @@ module Collapsium
307
318
  next
308
319
  end
309
320
 
310
- bases[base_path] = base_value
321
+ bases << [base_path, base_value]
311
322
  end
312
323
 
313
324
  # Only delete the "extends" keyword if we found all base.
@@ -315,6 +326,10 @@ module Collapsium
315
326
  value.delete("extends")
316
327
  end
317
328
 
329
+ return bases
330
+ end
331
+
332
+ def merge_base_values(root, value, bases)
318
333
  # We need to recursively resolve the base values before merging them into
319
334
  # value. To preserve the override order, we need to overwrite values when
320
335
  # merging bases...
@@ -328,11 +343,14 @@ module Collapsium
328
343
  value.recursive_merge!(merged_base, false)
329
344
 
330
345
  # Set the base if all is well.
331
- if value["base"].nil? and not bases.keys.empty?
332
- value["base"] = bases.keys
346
+ base_val = value["base"] || []
347
+ base_val += bases.map { |p, _| p }
348
+ base_val.uniq!
349
+ if base_val.empty?
350
+ return
333
351
  end
334
352
 
335
- root[path] = value
353
+ value["base"] = base_val
336
354
  end
337
355
  end # class Configuration
338
356
  end # module Config
@@ -9,6 +9,6 @@
9
9
  module Collapsium
10
10
  module Config
11
11
  # The current release version
12
- VERSION = "0.4.0".freeze
12
+ VERSION = "0.4.1".freeze
13
13
  end # module Config
14
14
  end # module Collapsium
@@ -104,6 +104,7 @@ describe Collapsium::Config::Configuration do
104
104
  expect(cfg["drivers.mock.mockoption"]).to eql 42
105
105
  expect(cfg["drivers.branch1.branch1option"]).to eql "foo"
106
106
  expect(cfg["drivers.branch2.branch2option"]).to eql "bar"
107
+ expect(cfg["drivers.branch3.branch3option"]).to eql "baz"
107
108
  expect(cfg["drivers.leaf.leafoption"]).to eql "baz"
108
109
 
109
110
  # Now test extended values
@@ -115,11 +116,16 @@ describe Collapsium::Config::Configuration do
115
116
  expect(cfg["drivers.leaf.branch1option"]).to eql "override" # not "foo" !
116
117
 
117
118
  expect(cfg["drivers.leaf.branch2option"]).to eql "bar"
119
+ expect(cfg["drivers.leaf.global_opt"]).to eql "set"
120
+
121
+ expect(cfg["drivers.branch3.global_opt"]).to eql "set"
118
122
 
119
123
  # Also test that all levels go back to base == mock
120
124
  expect(cfg["drivers.branch1.base"]).to eql %w(.drivers.mock)
121
- expect(cfg["drivers.branch2.base"]).to eql %w(.drivers.mock)
122
- expect(cfg["drivers.leaf.base"]).to eql %w(.drivers.mock)
125
+ expect(cfg["drivers.branch2.base"]).to eql %w(.drivers.mock .drivers.branch1)
126
+ expect(cfg["drivers.branch3.base"]).to eql %w(.global)
127
+ expect(cfg["drivers.leaf.base"]).to eql %w(.drivers.mock .drivers.branch1
128
+ .drivers.branch2 .global)
123
129
 
124
130
  # We expect that 'derived' is extended with '.other.base', too
125
131
  expect(cfg["derived.test.foo"]).to eql 'bar'
@@ -7,6 +7,9 @@
7
7
  #
8
8
  # so the order in this file has to be mock -> branch2 -> branch1 -> leaf
9
9
  ---
10
+ global:
11
+ global_opt: set
12
+
10
13
  drivers:
11
14
  mock:
12
15
  mockoption: 42
@@ -16,8 +19,11 @@ drivers:
16
19
  branch1:
17
20
  extends: mock
18
21
  branch1option: foo
22
+ branch3:
23
+ extends: .global
24
+ branch3option: baz
19
25
  leaf:
20
- extends: branch2
26
+ extends: branch2,.global
21
27
  leafoption: baz
22
28
  branch1option: override
23
29
  base_does_not_exist:
data/spec/spec_helper.rb CHANGED
@@ -1,9 +1,3 @@
1
- # Only start CodeClimate from travis
2
- if ENV['CODECLIMATE_REPO_TOKEN']
3
- require 'codeclimate-test-reporter'
4
- CodeClimate::TestReporter.start
5
- end
6
-
7
1
  # Always start SimpleCov
8
2
  require 'simplecov'
9
3
  SimpleCov.start
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.0
4
+ version: 0.4.1
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-04 00:00:00.000000000 Z
11
+ date: 2016-11-08 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler