mixlib-config 2.2.12 → 2.2.13
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/mixlib/config.rb +23 -16
- data/lib/mixlib/config/version.rb +1 -1
- data/spec/mixlib/config_spec.rb +12 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 031cf7147d6e707d31e246cddd1acd29d2a9cab3c98da3610ae7b8bf979492ab
|
4
|
+
data.tar.gz: 82668865d9b6b58504f6c7661c948481741aae975ad3f595710b8667556d51d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: da561b797c754df72b692df5206817f088be93ebc4af3ec70d43d515b01460b2a9bd43a7e1b346a42458d721e98d6ccfa3c23f05c3fd9939195a16a5dceb497b
|
7
|
+
data.tar.gz: 936108ecb06645ba066a60bdfed8f8671e5d54dc39111bde056f68618993b9c14f5e446cb90af4c0bfc6bd253297562f06eac2938b5d478b7c73cbe26624d55a
|
data/lib/mixlib/config.rb
CHANGED
@@ -70,7 +70,7 @@ module Mixlib
|
|
70
70
|
# filename<String>:: A filename to read from
|
71
71
|
def from_yaml(filename)
|
72
72
|
require "yaml"
|
73
|
-
from_hash(YAML.load(IO.read(filename))
|
73
|
+
from_hash(YAML.load(IO.read(filename)))
|
74
74
|
end
|
75
75
|
|
76
76
|
# Parses valid JSON structure into Ruby
|
@@ -79,7 +79,7 @@ module Mixlib
|
|
79
79
|
# filename<String>:: A filename to read from
|
80
80
|
def from_json(filename)
|
81
81
|
require "json"
|
82
|
-
from_hash(JSON.parse(IO.read(filename))
|
82
|
+
from_hash(JSON.parse(IO.read(filename)))
|
83
83
|
end
|
84
84
|
|
85
85
|
def from_toml(filename)
|
@@ -91,20 +91,8 @@ module Mixlib
|
|
91
91
|
#
|
92
92
|
# === Parameters
|
93
93
|
# hash<Hash>:: A Hash containing configuration
|
94
|
-
def from_hash(hash
|
95
|
-
|
96
|
-
|
97
|
-
to_dotted_hash(hash).each do |k, v|
|
98
|
-
if v.is_a? Array
|
99
|
-
ruby_translation << "#{k} #{v}"
|
100
|
-
elsif v.is_a? String
|
101
|
-
ruby_translation << "#{k} \"#{v}\""
|
102
|
-
else
|
103
|
-
ruby_translation << "#{k} #{v}"
|
104
|
-
end
|
105
|
-
end
|
106
|
-
|
107
|
-
instance_eval(ruby_translation.join("\n"), filename, 1)
|
94
|
+
def from_hash(hash)
|
95
|
+
apply_nested_hash(hash)
|
108
96
|
end
|
109
97
|
|
110
98
|
# Pass Mixlib::Config.configure() a block, and it will yield itself
|
@@ -567,6 +555,25 @@ module Mixlib
|
|
567
555
|
internal_get_or_set(method_symbol, *args)
|
568
556
|
end
|
569
557
|
|
558
|
+
protected
|
559
|
+
|
560
|
+
# Given a (nested) Hash, apply it to the config object and any contexts.
|
561
|
+
#
|
562
|
+
# This is preferable to converting it to the string representation with
|
563
|
+
# the #to_dotted_hash method above.
|
564
|
+
#
|
565
|
+
# === Parameters
|
566
|
+
# hash<Hash>:: The hash to apply to the config oject
|
567
|
+
def apply_nested_hash(hash)
|
568
|
+
hash.each do |k, v|
|
569
|
+
if v.is_a? Hash
|
570
|
+
internal_get(k.to_sym).apply_nested_hash(v)
|
571
|
+
else
|
572
|
+
internal_set(k.to_sym, v)
|
573
|
+
end
|
574
|
+
end
|
575
|
+
end
|
576
|
+
|
570
577
|
private
|
571
578
|
|
572
579
|
# Given a (nested) Hash, turn it into a single top-level hash using dots as
|
data/spec/mixlib/config_spec.rb
CHANGED
@@ -1277,14 +1277,25 @@ alpha = "beta"
|
|
1277
1277
|
let(:hash) do
|
1278
1278
|
{
|
1279
1279
|
"alpha" => "beta",
|
1280
|
+
gamma: "delta",
|
1280
1281
|
"foo" => %w{ bar baz matazz},
|
1282
|
+
"bar" => { "baz" => { "fizz" => "buzz" } },
|
1283
|
+
"windows_path" => 'C:\Windows Has Awful\Paths',
|
1281
1284
|
}
|
1282
1285
|
end
|
1283
1286
|
|
1284
|
-
it "
|
1287
|
+
it "configures the config object from a hash" do
|
1288
|
+
ConfigIt.config_context :bar do
|
1289
|
+
config_context :baz do
|
1290
|
+
default :fizz, "quux"
|
1291
|
+
end
|
1292
|
+
end
|
1285
1293
|
ConfigIt.from_hash(hash)
|
1286
1294
|
expect(ConfigIt.foo).to eql(%w{ bar baz matazz })
|
1287
1295
|
expect(ConfigIt.alpha).to eql("beta")
|
1296
|
+
expect(ConfigIt.gamma).to eql("delta")
|
1297
|
+
expect(ConfigIt[:bar][:baz][:fizz]).to eql("buzz")
|
1298
|
+
expect(ConfigIt.windows_path).to eql('C:\Windows Has Awful\Paths')
|
1288
1299
|
end
|
1289
1300
|
end
|
1290
1301
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: mixlib-config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.2.
|
4
|
+
version: 2.2.13
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Chef Software, Inc.
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-07-
|
11
|
+
date: 2018-07-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: tomlrb
|