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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: e49d199c25ed417933cc95a2868d154e4f0fbc631aef9d1c5f05310ebbdbbe56
4
- data.tar.gz: 4307e6ce5ff263812c96055084d328901587139f82ca213a2ec1272208931150
3
+ metadata.gz: 031cf7147d6e707d31e246cddd1acd29d2a9cab3c98da3610ae7b8bf979492ab
4
+ data.tar.gz: 82668865d9b6b58504f6c7661c948481741aae975ad3f595710b8667556d51d7
5
5
  SHA512:
6
- metadata.gz: cdfcc6a831af4bd63216614a7e191152cd5f9dee67e7e87a2775d5d7c766b7c6e8f667ec45062400688e2cc746e2936041087f4e1de85e72f91b10c71c7a36de
7
- data.tar.gz: ac0b067a839675c594663b0fa5a91cd66059dc807775dfaacceae62f77efb975d3f26db0ca1781571bfd73c97c5b09bea921fe04fc7e0cf3af48e617917241f5
6
+ metadata.gz: da561b797c754df72b692df5206817f088be93ebc4af3ec70d43d515b01460b2a9bd43a7e1b346a42458d721e98d6ccfa3c23f05c3fd9939195a16a5dceb497b
7
+ data.tar.gz: 936108ecb06645ba066a60bdfed8f8671e5d54dc39111bde056f68618993b9c14f5e446cb90af4c0bfc6bd253297562f06eac2938b5d478b7c73cbe26624d55a
@@ -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)), 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)), 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, filename = "in_memory")
95
- ruby_translation = []
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
@@ -19,7 +19,7 @@
19
19
  module Mixlib
20
20
  module Config
21
21
 
22
- VERSION = "2.2.12"
22
+ VERSION = "2.2.13"
23
23
 
24
24
  end
25
25
  end
@@ -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 "translates the Hash into method-style" do
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.12
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-06 00:00:00.000000000 Z
11
+ date: 2018-07-11 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: tomlrb