Get the value of a configuration option
config_option<Symbol> |
The configuration option to return |
value |
The value of the configuration option |
<ArgumentError> |
If the configuration option does not exist |
# File lib/mixlib/config.rb, line 58 def [](config_option) self.configuration[config_option.to_sym] end
Set the value of a configuration option
config_option<Symbol> |
The configuration option to set (within the []) |
value |
The value for the configuration option |
value |
The new value of the configuration option |
# File lib/mixlib/config.rb, line 70 def []=(config_option, value) internal_set(config_option,value) end
metaprogramming to ensure that the slot for method_symbol gets set to value after any other logic is run
method_symbol<Symbol> |
Name of the method (variable setter) |
blk<Block> |
logic block to run in setting slot method_symbol to value |
value<Object> |
Value to be set in config hash |
# File lib/mixlib/config.rb, line 138 def config_attr_writer(method_symbol, &blk) meta = class << self; self; end method_name = "#{method_symbol.to_s}=".to_sym meta.send :define_method, method_name do |value| self.configuration[method_symbol] = blk.call(value) end end
Pass Mixlib::Config.configure() a block, and it will yield self.configuration.
<block> |
A block that is sent self.configuration as its argument |
# File lib/mixlib/config.rb, line 44 def configure(&block) block.call(self.configuration) 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.
<string> |
A filename to read from |
# File lib/mixlib/config.rb, line 36 def from_file(filename) self.instance_eval(IO.read(filename), filename, 1) end
Check if Mixlib::Config has a configuration option.
key<Symbol> |
The configuration option to check for |
<True> |
If the configuration option exists |
<False> |
If the configuration option does not exist |
# File lib/mixlib/config.rb, line 82 def has_key?(key) self.configuration.has_key?(key.to_sym) end
Creates a shallow copy of the internal hash
result of Hash#dup
# File lib/mixlib/config.rb, line 109 def hash_dup self.configuration.dup end
Return the set of config hash keys
result of Hash#keys
# File lib/mixlib/config.rb, line 101 def keys self.configuration.keys end
Merge an incoming hash with our config options
hash<Hash> |
The incoming hash |
result of Hash#merge!
# File lib/mixlib/config.rb, line 93 def merge!(hash) self.configuration.merge!(hash) end
Allows for simple lookups and setting of configuration options via method calls on Mixlib::Config. If there any arguments to the method, they are used to set the value of the configuration option. Otherwise, it's a simple get operation.
method_symbol<Symbol> |
The method called. Must match a configuration option. |
*args |
Any arguments passed to the method |
value |
The value of the configuration option. |
<ArgumentError> |
If the method_symbol does not match a configuration option. |
# File lib/mixlib/config.rb, line 159 def method_missing(method_symbol, *args) num_args = args.length # Setting if num_args > 0 method_symbol = $1.to_sym unless (method_symbol.to_s =~ /(.+)=$/).nil? internal_set method_symbol, (num_args == 1 ? args[0] : args) end # Returning self.configuration[method_symbol] end
Internal dispatch setter, calling either the real defined method or setting the hash value directly
method_symbol<Symbol> |
Name of the method (variable setter) |
value<Object> |
Value to be set in config hash |
# File lib/mixlib/config.rb, line 120 def internal_set(method_symbol,value) method_name = method_symbol.id2name if self.respond_to?("#{method_name}=".to_sym) self.send("#{method_name}=", value) else self.configuration[method_symbol] = value end end
Generated with the Darkfish Rdoc Generator 2.