config_hound 1.0.0 → 1.1.0

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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 889819e5d375efbd4ba6f012a02332fe2f79c0d1
4
- data.tar.gz: f0b888501712c79f5e0f4f7e6d0db269ee7eda0a
3
+ metadata.gz: cb89f3e818a6b9ceb8e00aa4d10702425efb7e03
4
+ data.tar.gz: bb2391444edc55b0639372c426a00685f7c5fdbb
5
5
  SHA512:
6
- metadata.gz: a53953b012bf1acb2eb819d2a32265edf410a2691cb933b29706a9c82964e189c17b16aa6a282c2c45afd9c3c99beab581c3c949465a697b5d03041d62f9d7ef
7
- data.tar.gz: 674d5e2e1c9f45ca97f2a3a2a8777f14ef4e9454bd7dfa6f651db9afce1504b82f95c88dcb7de0a4cbd7b9ca650dccee40f2a30c383817530cb17b732014185a
6
+ metadata.gz: 87e70b81bef285e6ef51d55d314794d2b6606e4ab1bcfeab8d640ffee49f21968be1b23db14f9e085b1b93febe3dbcd8942bfa3df8728d6b435bf3763c15d1db
7
+ data.tar.gz: d85b9c7a397c671e0df5ef9693f80781d822029d7e9e793b1ed7621d21bbd065f6789284f7521ca4f8755514b5f95c06a5d6448b3bbf98a5e6f27efa58b6399a
@@ -1,4 +1,3 @@
1
- require "config_hound/parser"
2
1
  require "config_hound/resource"
3
2
 
4
3
  module ConfigHound
@@ -7,32 +6,37 @@ module ConfigHound
7
6
 
8
7
  DEFAULT_INCLUDE_KEY = "_include"
9
8
 
10
- def self.load(path, options = {})
11
- new(path, options).load
9
+ def self.load(paths, options = {})
10
+ data = {}
11
+ loader = new(data, options)
12
+ Array(paths).each do |path|
13
+ loader.load(path)
14
+ end
15
+ data
12
16
  end
13
17
 
14
- def initialize(path, options)
15
- @resource = Resource.new(path.to_s)
18
+ def initialize(data, options)
19
+ @data = data
16
20
  @include_key = options.fetch(:include_key, DEFAULT_INCLUDE_KEY)
17
21
  end
18
22
 
19
- def load
20
- data = Parser.parse(resource.read, resource.format)
21
- Array(data.delete(include_key)).each do |i|
22
- defaults = Loader.load(resource.resolve(i))
23
- include_into!(data, defaults)
23
+ def load(path)
24
+ resource = Resource.new(path.to_s)
25
+ include_into!(data, resource.load)
26
+ includes = Array(data.delete(include_key))
27
+ includes.each do |i|
28
+ load(resource.resolve(i))
24
29
  end
25
- data
26
30
  end
27
31
 
28
32
  private
29
33
 
30
- attr_reader :resource
34
+ attr_reader :data
31
35
  attr_reader :include_key
32
36
 
33
- def include_into!(data, defaults)
34
- return unless data.is_a?(Hash) && defaults.is_a?(Hash)
35
- defaults.each do |key, value|
37
+ def include_into!(data, more_data)
38
+ return unless data.is_a?(Hash) && more_data.is_a?(Hash)
39
+ more_data.each do |key, value|
36
40
  if data.has_key?(key)
37
41
  include_into!(data[key], value)
38
42
  else
@@ -1,3 +1,4 @@
1
+ require "config_hound/parser"
1
2
  require "open-uri"
2
3
  require "uri"
3
4
 
@@ -33,6 +34,10 @@ module ConfigHound
33
34
  File.extname(uri.to_s)[1..-1]
34
35
  end
35
36
 
37
+ def load
38
+ Parser.parse(read, format)
39
+ end
40
+
36
41
  private
37
42
 
38
43
  attr_reader :uri
@@ -1,3 +1,3 @@
1
1
  module ConfigHound
2
- VERSION = "1.0.0"
2
+ VERSION = "1.1.0"
3
3
  end
@@ -164,6 +164,34 @@ describe ConfigHound do
164
164
 
165
165
  end
166
166
 
167
+ context "with multiple includes" do
168
+
169
+ given_resource "config.yml", %{
170
+ _include:
171
+ - fileA.yml
172
+ - fileB.yml
173
+ }
174
+
175
+ given_resource "fileA.yml", %{
176
+ source: A
177
+ fromA: true
178
+ }
179
+
180
+ given_resource "fileB.yml", %{
181
+ source: B
182
+ fromB: true
183
+ }
184
+
185
+ it "loads both files" do
186
+ expect(config).to have_key("fromA")
187
+ expect(config).to have_key("fromB")
188
+ end
189
+
190
+ it "favours earliest included file" do
191
+ expect(config["source"]).to eq("A")
192
+ end
193
+
194
+ end
167
195
  end
168
196
 
169
197
 
@@ -0,0 +1,32 @@
1
+ require "spec_helper"
2
+
3
+ require "config_hound"
4
+
5
+ describe ConfigHound do
6
+
7
+ def load(path)
8
+ ConfigHound.load(path)
9
+ end
10
+
11
+ let(:config) { load(["fileA.yml", "fileB.yml"]) }
12
+
13
+ given_resource "fileA.yml", %{
14
+ source: A
15
+ fromA: true
16
+ }
17
+
18
+ given_resource "fileB.yml", %{
19
+ source: B
20
+ fromB: true
21
+ }
22
+
23
+ it "loads both files" do
24
+ expect(config).to have_key("fromA")
25
+ expect(config).to have_key("fromB")
26
+ end
27
+
28
+ it "favours earliest included file" do
29
+ expect(config["source"]).to eq("A")
30
+ end
31
+
32
+ end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: config_hound
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.0
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Mike Williams
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-03-19 00:00:00.000000000 Z
11
+ date: 2015-06-10 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -60,6 +60,7 @@ files:
60
60
  - spec/config_hound/resource_spec.rb
61
61
  - spec/features/basics_spec.rb
62
62
  - spec/features/include_spec.rb
63
+ - spec/features/multi_file_spec.rb
63
64
  - spec/spec_helper.rb
64
65
  homepage: https://github.com/mdub/config_hound
65
66
  licenses:
@@ -81,7 +82,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
81
82
  version: '0'
82
83
  requirements: []
83
84
  rubyforge_project:
84
- rubygems_version: 2.2.2
85
+ rubygems_version: 2.4.5
85
86
  signing_key:
86
87
  specification_version: 4
87
88
  summary: Sniffs out config, wherever it may be.
@@ -89,4 +90,5 @@ test_files:
89
90
  - spec/config_hound/resource_spec.rb
90
91
  - spec/features/basics_spec.rb
91
92
  - spec/features/include_spec.rb
93
+ - spec/features/multi_file_spec.rb
92
94
  - spec/spec_helper.rb