cheffish 4.1.1 → 5.0.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/cheffish/merged_config.rb +4 -2
- data/lib/cheffish/version.rb +1 -1
- data/spec/functional/merged_config_spec.rb +41 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c319e55f4faad24ef6fb157b9fc9f903c47cc466
|
4
|
+
data.tar.gz: bf2cb3572b55f1805eedc069e2ee0ac10078aa91
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e73940e8d05a661d28a8f9b616b1b7ffa07453b28ca60c0dd4af2968a609e0147d97eebfee0e513c9467c592af500dd19862ea6be0e00d7342551a5bc1fde41
|
7
|
+
data.tar.gz: 4731f43daf08d9943a46fd004145f4880f71e1ccc706dbad6512dfd795df2178912916f5e15d05364fa05737a678b7f22d47e9e9cb9046ab3ace93c16e334c76
|
@@ -1,8 +1,10 @@
|
|
1
|
+
require "chef/mash"
|
2
|
+
|
1
3
|
module Cheffish
|
2
4
|
class MergedConfig
|
3
5
|
def initialize(*configs)
|
4
|
-
@configs = configs
|
5
|
-
@merge_arrays =
|
6
|
+
@configs = configs.map { |config| Chef::Mash.from_hash config }
|
7
|
+
@merge_arrays = Chef::Mash.new
|
6
8
|
end
|
7
9
|
|
8
10
|
include Enumerable
|
data/lib/cheffish/version.rb
CHANGED
@@ -6,6 +6,24 @@ describe "merged_config" do
|
|
6
6
|
Cheffish::MergedConfig.new({ :test => "val" })
|
7
7
|
end
|
8
8
|
|
9
|
+
let(:collision) do
|
10
|
+
c1 = { :test1 => "c1.1", "test2" => "c1.2" }
|
11
|
+
c2 = { "test1" => "c2.1", "test3" => "c2.3" }
|
12
|
+
Cheffish::MergedConfig.new(c1, c2)
|
13
|
+
end
|
14
|
+
|
15
|
+
let(:config_mismatch) do
|
16
|
+
c1 = { :test => { :test => "val" } }
|
17
|
+
c2 = { :test => [2, 3, 4] }
|
18
|
+
Cheffish::MergedConfig.new(c1, c2)
|
19
|
+
end
|
20
|
+
|
21
|
+
let(:config_hashes) do
|
22
|
+
c1 = { :test => { :test => "val" } }
|
23
|
+
c2 = { :test => { :test2 => "val2" } }
|
24
|
+
Cheffish::MergedConfig.new(c1, c2)
|
25
|
+
end
|
26
|
+
|
9
27
|
it "returns value in config" do
|
10
28
|
expect(config.test).to eq("val")
|
11
29
|
end
|
@@ -15,6 +33,28 @@ describe "merged_config" do
|
|
15
33
|
end
|
16
34
|
|
17
35
|
it "has an informative string representation" do
|
18
|
-
expect("#{config}").to eq("{
|
36
|
+
expect("#{config}").to eq("{\"test\"=>\"val\"}")
|
37
|
+
end
|
38
|
+
|
39
|
+
it "has indifferent str/sym access" do
|
40
|
+
expect(config["test"]).to eq("val")
|
41
|
+
end
|
42
|
+
|
43
|
+
it "respects precedence between the different configs" do
|
44
|
+
expect(collision["test1"]).to eq("c1.1")
|
45
|
+
expect(collision[:test1]).to eq("c1.1")
|
46
|
+
end
|
47
|
+
|
48
|
+
it "merges the configs" do
|
49
|
+
expect(collision[:test2]).to eq("c1.2")
|
50
|
+
expect(collision[:test3]).to eq("c2.3")
|
51
|
+
end
|
52
|
+
|
53
|
+
it "handle merged value type mismatch" do
|
54
|
+
expect(config_mismatch[:test]).to eq("test" => "val")
|
55
|
+
end
|
56
|
+
|
57
|
+
it "merges values when they're hashes" do
|
58
|
+
expect(config_hashes[:test].keys).to eq(%w{test test2})
|
19
59
|
end
|
20
60
|
end
|