summaryrefslogtreecommitdiff
path: root/lib/mixlib/config.rb
diff options
context:
space:
mode:
authorChristopher Brown <cb@opscode.com>2009-08-26 12:53:57 -0700
committerChristopher Brown <cb@opscode.com>2009-08-26 12:53:57 -0700
commit4804a909ab7b7d1a8f290869ed09ccf5f330f2bf (patch)
tree1f0cd0ecdf010393c9d7667f8f4e06dff6a37d81 /lib/mixlib/config.rb
parentfa4bdd1a6b39c7dc4be804d6c871d28a552afbcc (diff)
parent89b9dac377a441acd9c41b15482320ffcb03779e (diff)
downloadmixlib-config-class_instance_variable.tar.gz
integrate nuo's class instance variable with attribute setter changesclass_instance_variable
Diffstat (limited to 'lib/mixlib/config.rb')
-rw-r--r--lib/mixlib/config.rb31
1 files changed, 18 insertions, 13 deletions
diff --git a/lib/mixlib/config.rb b/lib/mixlib/config.rb
index 2fd0c94..14699b0 100644
--- a/lib/mixlib/config.rb
+++ b/lib/mixlib/config.rb
@@ -1,5 +1,7 @@
#
# Author:: Adam Jacob (<adam@opscode.com>)
+# Author:: Nuo Yan (<nuo@opscode.com>)
+# Author:: Christopher Brown (<cb@opscode.com>)
# Copyright:: Copyright (c) 2008 Opscode, Inc.
# License:: Apache License, Version 2.0
#
@@ -24,8 +26,11 @@ end
module Mixlib
module Config
-
- @@configuration = Hash.new
+
+ def self.extended(base)
+ class << base; attr_accessor :configuration; end
+ base.configuration = Hash.new
+ end
# Loads a given ruby file, and runs instance_eval against it in the context of the current
# object.
@@ -38,12 +43,12 @@ module Mixlib
self.instance_eval(IO.read(filename), filename, 1)
end
- # Pass Mixlib::Config.configure() a block, and it will yield @@configuration.
+ # Pass Mixlib::Config.configure() a block, and it will yield self.configuration.
#
# === Parameters
- # <block>:: A block that is sent @@configuration as its argument
+ # <block>:: A block that is sent self.configuration as its argument
def configure(&block)
- block.call(@@configuration)
+ block.call(self.configuration)
end
# Get the value of a configuration option
@@ -57,7 +62,7 @@ module Mixlib
# === Raises
# <ArgumentError>:: If the configuration option does not exist
def [](config_option)
- @@configuration[config_option.to_sym]
+ self.configuration[config_option.to_sym]
end
# Set the value of a configuration option
@@ -81,7 +86,7 @@ module Mixlib
# <True>:: If the configuration option exists
# <False>:: If the configuration option does not exist
def has_key?(key)
- @@configuration.has_key?(key.to_sym)
+ self.configuration.has_key?(key.to_sym)
end
# Merge an incoming hash with our config options
@@ -92,7 +97,7 @@ module Mixlib
# === Returns
# result of Hash#merge!
def merge!(hash)
- @@configuration.merge!(hash)
+ self.configuration.merge!(hash)
end
# Return the set of config hash keys
@@ -100,7 +105,7 @@ module Mixlib
# === Returns
# result of Hash#keys
def keys
- @@configuration.keys
+ self.configuration.keys
end
# Creates a shallow copy of the internal hash
@@ -108,7 +113,7 @@ module Mixlib
# === Returns
# result of Hash#dup
def hash_dup
- @@configuration.dup
+ self.configuration.dup
end
# Internal dispatch setter, calling either the real defined method or setting the
@@ -123,7 +128,7 @@ module Mixlib
if (self.public_methods - ["[]="]).include?("#{method_name}=")
self.send("#{method_name}=", value)
else
- @@configuration[method_symbol] = value
+ self.configuration[method_symbol] = value
end
end
@@ -139,7 +144,7 @@ module Mixlib
def config_attr_writer(method_symbol, &blk)
method_name = "#{method_symbol.to_s}="
meta_def method_name do |value|
- @@configuration[method_symbol] = blk.call(value)
+ self.configuration[method_symbol] = blk.call(value)
end
end
@@ -165,7 +170,7 @@ module Mixlib
end
# Returning
- @@configuration[method_symbol]
+ self.configuration[method_symbol]
end
end