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 +4 -4
- data/lib/config_hound/loader.rb +19 -15
- data/lib/config_hound/resource.rb +5 -0
- data/lib/config_hound/version.rb +1 -1
- data/spec/features/include_spec.rb +28 -0
- data/spec/features/multi_file_spec.rb +32 -0
- metadata +5 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: cb89f3e818a6b9ceb8e00aa4d10702425efb7e03
|
4
|
+
data.tar.gz: bb2391444edc55b0639372c426a00685f7c5fdbb
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87e70b81bef285e6ef51d55d314794d2b6606e4ab1bcfeab8d640ffee49f21968be1b23db14f9e085b1b93febe3dbcd8942bfa3df8728d6b435bf3763c15d1db
|
7
|
+
data.tar.gz: d85b9c7a397c671e0df5ef9693f80781d822029d7e9e793b1ed7621d21bbd065f6789284f7521ca4f8755514b5f95c06a5d6448b3bbf98a5e6f27efa58b6399a
|
data/lib/config_hound/loader.rb
CHANGED
@@ -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(
|
11
|
-
|
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(
|
15
|
-
@
|
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
|
-
|
21
|
-
|
22
|
-
|
23
|
-
|
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 :
|
34
|
+
attr_reader :data
|
31
35
|
attr_reader :include_key
|
32
36
|
|
33
|
-
def include_into!(data,
|
34
|
-
return unless data.is_a?(Hash) &&
|
35
|
-
|
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
|
data/lib/config_hound/version.rb
CHANGED
@@ -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.
|
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-
|
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.
|
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
|