lib/mixlib/config.rb in mixlib-config-2.2.1 vs lib/mixlib/config.rb in mixlib-config-2.2.2
- old
+ new
@@ -16,15 +16,15 @@
# WITHOUT WARRANTIES OR CONDITIONS OF ANY KIND, either express or implied.
# See the License for the specific language governing permissions and
# limitations under the License.
#
-require 'mixlib/config/version'
-require 'mixlib/config/configurable'
-require 'mixlib/config/unknown_config_option_error'
-require 'mixlib/config/reopened_config_context_with_configurable_error'
-require 'mixlib/config/reopened_configurable_with_config_context_error'
+require "mixlib/config/version"
+require "mixlib/config/configurable"
+require "mixlib/config/unknown_config_option_error"
+require "mixlib/config/reopened_config_context_with_configurable_error"
+require "mixlib/config/reopened_configurable_with_config_context_error"
module Mixlib
module Config
def self.extended(base)
class << base; attr_accessor :configuration; end
@@ -32,12 +32,17 @@
class << base; attr_accessor :config_contexts; end
class << base; attr_accessor :config_parent; end
base.configuration = Hash.new
base.configurables = Hash.new
base.config_contexts = Hash.new
+ base.initialize_mixlib_config
end
+ def initialize_mixlib_config
+ @config_strict_mode = nil
+ end
+
# Loads a given ruby file, and runs instance_eval against it in the context of the current
# object.
#
# Raises an IOError if the file cannot be found, or is not readable.
#
@@ -50,11 +55,11 @@
# Pass Mixlib::Config.configure() a block, and it will yield itself
#
# === Parameters
# block<Block>:: A block that is called with self.configuration as the argument.
def configure(&block)
- block.call(self.configuration)
+ yield(self.configuration)
end
# Get the value of a config option
#
# === Parameters
@@ -278,11 +283,11 @@
end
configurables[symbol] = Configurable.new(symbol)
define_attr_accessor_methods(symbol)
end
if block
- block.call(configurables[symbol])
+ yield(configurables[symbol])
end
configurables[symbol]
end
# Allows you to create a new config context where you can define new
@@ -401,11 +406,11 @@
#
# === Parameters
# symbol<Symbol>:: Name of the method (variable setter)
# value<Object>:: Value to be set in config hash
#
- def internal_set(symbol,value)
+ 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)
else
@@ -431,11 +436,11 @@
end
configuration[symbol]
end
end
- def internal_get_or_set(symbol,*args)
+ def internal_get_or_set(symbol, *args)
num_args = args.length
# Setting
if num_args > 0
internal_set(symbol, num_args == 1 ? args[0] : args)
end
@@ -446,10 +451,10 @@
def define_attr_accessor_methods(symbol)
# When Ruby 1.8.7 is no longer supported, this stuff can be done with define_singleton_method!
meta = class << self; self; end
# Setter
- meta.send :define_method, "#{symbol.to_s}=".to_sym do |value|
+ 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)