lib/mixlib/config.rb in mixlib-config-2.2.3 vs lib/mixlib/config.rb in mixlib-config-2.2.4

- old
+ new

@@ -172,10 +172,11 @@ context_result = context.save(include_defaults) result[key] = context_result if context_result.size != 0 || include_defaults end result end + alias :to_hash :save # Restore non-default values from the given hash. # # === Parameters # hash<Hash>: a hash in the same format as output by save. @@ -414,11 +415,11 @@ # def internal_set(symbol, value) 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}.") elsif config_strict_mode raise UnknownConfigOptionError, "Cannot set unsupported config value #{symbol}." @@ -459,11 +460,21 @@ # Setter meta.send :define_method, "#{symbol}=".to_sym do |value| internal_set(symbol, value) end # Getter - meta.send :define_method, symbol do |*args| - internal_get_or_set(symbol, *args) + meta.send :define_method, symbol do |*args, &block| + # If a block was given, eval it in the context + if block + # If the block expects no arguments, then instance_eval + if block.arity == 0 + internal_get(symbol).instance_eval(&block) + else # yield to the block + block.yield(internal_get(symbol)) + end + else + internal_get_or_set(symbol, *args) + end end end end end