diff options
author | Matt Wrock <matt@mattwrock.com> | 2016-08-31 16:18:19 -0700 |
---|---|---|
committer | Matt Wrock <matt@mattwrock.com> | 2016-08-31 16:18:19 -0700 |
commit | 61008c33ab6de5dc21fe1de15ce08996f000dc9f (patch) | |
tree | 7ef44280dbbeec965d6847319dba2ded53bbff6e | |
parent | ae2f0b958e21a68177ffab0312a636e36b004e2b (diff) | |
download | mixlib-config-61008c33ab6de5dc21fe1de15ce08996f000dc9f.tar.gz |
allow a config context to be set from another config contexthash
-rw-r--r-- | lib/mixlib/config.rb | 3 | ||||
-rw-r--r-- | spec/mixlib/config_spec.rb | 10 |
2 files changed, 11 insertions, 2 deletions
diff --git a/lib/mixlib/config.rb b/lib/mixlib/config.rb index 517aae7..4927153 100644 --- a/lib/mixlib/config.rb +++ b/lib/mixlib/config.rb @@ -174,6 +174,7 @@ module Mixlib end result end + alias :to_hash :save # Restore non-default values from the given hash. # @@ -416,7 +417,7 @@ module Mixlib if configurables.has_key?(symbol) configurables[symbol].set(self.configuration, value) elsif config_contexts.has_key?(symbol) - config_contexts[symbol].restore(value) + config_contexts[symbol].restore(value.to_hash) else if config_strict_mode == :warn Chef::Log.warn("Setting unsupported config value #{symbol}.") diff --git a/spec/mixlib/config_spec.rb b/spec/mixlib/config_spec.rb index 9948b7f..9879a2b 100644 --- a/spec/mixlib/config_spec.rb +++ b/spec/mixlib/config_spec.rb @@ -850,12 +850,20 @@ describe Mixlib::Config do expect(@klass.blah.yarr.y).to eql(6) end - it "resmoves added properties not included in saved state" do + it "removes added properties not included in saved state" do @klass.blah.yarr.z = 12 @klass.restore( :blah => { :yarr => { :x => 10 } } ) expect(@klass.blah.yarr.x).to eql(10) expect(@klass.blah.yarr.z).to eql(nil) end + + it "can set a config context from another context" do + @klass.blah.blyme = { :x => 7 } + blyme = @klass.blah.blyme + @klass.blah.yarr.x = 12 + @klass.blah.yarr = blyme + expect(@klass.blah.yarr.x).to eql(7) + end end describe "When a config_context with no defaulted values exists" do |