diff options
-rw-r--r-- | lib/mixlib/config.rb | 24 |
1 files changed, 18 insertions, 6 deletions
diff --git a/lib/mixlib/config.rb b/lib/mixlib/config.rb index 40c5926..4654c7e 100644 --- a/lib/mixlib/config.rb +++ b/lib/mixlib/config.rb @@ -177,16 +177,28 @@ module Mixlib # Restore non-default values from the given hash. # - # This method is the equivalent of +reset+ followed by +merge!(hash)+. - # # === Parameters # hash<Hash>: a hash in the same format as output by save. - # + # mirrored_context<Config>: a config with schema to mirror + # # === Returns # self - def restore(hash) - reset - merge!(hash) + def restore(hash, mirrored_context = self) + new_config = Hash.new + new_contexts = Hash.new + hash.each do |key, value| + if mirrored_context.config_contexts.has_key?(key) + context = Class.new + context.extend(::Mixlib::Config) + context.config_parent = self + context.restore(value, mirrored_context.config_contexts[key]) + new_contexts[key] = context + else + new_config[key] = value + end + end + self.configuration = new_config + self.config_contexts = new_contexts end # Merge an incoming hash with our config options |