lib/mixlib/config.rb in mixlib-config-2.2.13 vs lib/mixlib/config.rb in mixlib-config-2.2.18

- old
+ new

@@ -139,18 +139,18 @@ # # === Returns # <True>:: If the config option exists # <False>:: If the config option does not exist def key?(key) - configuration.has_key?(key.to_sym) || config_contexts.has_key?(key.to_sym) + configuration.key?(key.to_sym) || config_contexts.key?(key.to_sym) end alias_method :has_key?, :key? def is_default?(key) symbol = key.to_sym - if configurables.has_key?(symbol) + if configurables.key?(symbol) configurables[symbol].is_default?(configuration) else raise ArgumentError, "config option must exist, and not be a context to check for default values" end end @@ -248,31 +248,31 @@ # hash<Hash>: a hash in the same format as output by save. # # === Returns # self def restore(hash) - self.configuration = hash.reject { |key, value| config_contexts.has_key?(key) } + self.configuration = hash.reject { |key, value| config_contexts.key?(key) } config_contexts.each do |key, config_context| - if hash.has_key?(key) + if hash.key?(key) config_context.restore(hash[key]) else config_context.reset end end config_context_lists.each do |key, meta| meta[:values] = [] - if hash.has_key?(key) + if hash.key?(key) hash[key].each do |val| context = define_context(meta[:definition_blocks]) context.restore(val) meta[:values] << context end end end config_context_hashes.each do |key, meta| meta[:values] = {} - if hash.has_key?(key) + if hash.key?(key) hash[key].each do |vkey, val| context = define_context(meta[:definition_blocks]) context.restore(val) meta[:values][vkey] = context end @@ -287,11 +287,11 @@ # # === Returns # self def merge!(hash) hash.each do |key, value| - if config_contexts.has_key?(key) + if config_contexts.key?(key) # Grab the config context and let internal_get cache it if so desired config_contexts[key].restore(value) else configuration[key] = value end @@ -367,11 +367,11 @@ # # === Returns # The value of the config option. def configurable(symbol, &block) unless configurables[symbol] - if config_contexts.has_key?(symbol) + if config_contexts.key?(symbol) raise ReopenedConfigContextWithConfigurableError, "Cannot redefine config_context #{symbol} as a configurable value" end configurables[symbol] = Configurable.new(symbol) define_attr_accessor_methods(symbol) end @@ -395,15 +395,15 @@ # === Parameters # symbol<Symbol>: the name of the context # block<Block>: a block that will be run in the context of this new config # class. def config_context(symbol, &block) - if configurables.has_key?(symbol) + if configurables.key?(symbol) raise ReopenedConfigurableWithConfigContextError, "Cannot redefine config value #{symbol} with a config context" end - if config_contexts.has_key?(symbol) + if config_contexts.key?(symbol) context = config_contexts[symbol] else context = Class.new context.extend(::Mixlib::Config) context.config_parent = self @@ -433,15 +433,15 @@ # symbol<Symbol>: the plural name for contexts in the list # symbol<Symbol>: the singular name for contexts in the list # block<Block>: a block that will be run in the context of this new config # class. def config_context_list(plural_symbol, singular_symbol, &block) - if configurables.has_key?(plural_symbol) + if configurables.key?(plural_symbol) raise ReopenedConfigurableWithConfigContextError, "Cannot redefine config value #{plural_symbol} with a config context" end - unless config_context_lists.has_key?(plural_symbol) + unless config_context_lists.key?(plural_symbol) config_context_lists[plural_symbol] = { definition_blocks: [], values: [], } define_list_attr_accessor_methods(plural_symbol, singular_symbol) @@ -465,15 +465,15 @@ # symbol<Symbol>: the plural name for contexts in the list # symbol<Symbol>: the singular name for contexts in the list # block<Block>: a block that will be run in the context of this new config # class. def config_context_hash(plural_symbol, singular_symbol, &block) - if configurables.has_key?(plural_symbol) + if configurables.key?(plural_symbol) raise ReopenedConfigurableWithConfigContextError, "Cannot redefine config value #{plural_symbol} with a config context" end - unless config_context_hashes.has_key?(plural_symbol) + unless config_context_hashes.key?(plural_symbol) config_context_hashes[plural_symbol] = { definition_blocks: [], values: {}, } define_hash_attr_accessor_methods(plural_symbol, singular_symbol) @@ -602,13 +602,13 @@ # === Parameters # symbol<Symbol>:: Name of the method (variable setter) # value<Object>:: Value to be set in config hash # def internal_set(symbol, value) - if configurables.has_key?(symbol) + if configurables.key?(symbol) configurables[symbol].set(configuration, value) - elsif config_contexts.has_key?(symbol) + elsif config_contexts.key?(symbol) 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 @@ -617,17 +617,17 @@ configuration[symbol] = value end end def internal_get(symbol) - if configurables.has_key?(symbol) + if configurables.key?(symbol) configurables[symbol].get(configuration) - elsif config_contexts.has_key?(symbol) + elsif config_contexts.key?(symbol) config_contexts[symbol] - elsif config_context_lists.has_key?(symbol) + elsif config_context_lists.key?(symbol) config_context_lists[symbol] - elsif config_context_hashes.has_key?(symbol) + elsif config_context_hashes.key?(symbol) config_context_hashes[symbol] else if config_strict_mode == :warn Chef::Log.warn("Reading unsupported config value #{symbol}.") elsif config_strict_mode @@ -700,10 +700,10 @@ internal_get(plural_symbol)[:values] end # Adds a single new context to the list meta.send :define_method, singular_symbol do |key, &block| context_hash_details = internal_get(plural_symbol) - context = if context_hash_details[:values].has_key? key + context = if context_hash_details[:values].key? key context_hash_details[:values][key] else new_context = define_context(context_hash_details[:definition_blocks]) context_hash_details[:values][key] = new_context new_context