class Omnibus::Config
Public Class Methods
default(key, default = NullArgumentable::NULL, &block)
click to toggle source
@macro default
@method $1(value = NULL)
@param [Symbol] key
the name of the configuration value to create
@param [Object] default
the default value
@param [Proc] block
a block to be called for the default value. If the block is provided, the +default+ attribute is ignored
# File lib/omnibus/config.rb, line 51 def default(key, default = NullArgumentable::NULL, &block) # This is a class method, which delegates to the instance method define_singleton_method(key) do |value = NullArgumentable::NULL| instance.send(key, value) end # This is an instance method, but this is a singleton object ;) define_method(key) do |value = NullArgumentable::NULL| set_or_return(key, value, default, &block) end # All config options should be avaiable as DSL methods expose(key) end
key?(key)
click to toggle source
Check if the configuration includes the given key.
@param [Symbol] key
@return [true, false]
# File lib/omnibus/config.rb, line 73 def key?(key) public_method_defined?(key.to_sym) end
Also aliased as: has_key?
load(filepath)
click to toggle source
@param [String] filepath
the path to the config definition to load from disk
@return [Config]
# File lib/omnibus/config.rb, line 35 def load(filepath) evaluate_file(instance, filepath) end
reset!()
click to toggle source
Reset the current configuration values. This method will unset any “stored” or memorized configuration values.
@return [true]
# File lib/omnibus/config.rb, line 84 def reset! instance.instance_variables.each do |instance_variable| instance.send(:remove_instance_variable, instance_variable) end true end
Private Instance Methods
set_or_return(key, value = NULL, default = NULL, &block)
click to toggle source
# File lib/omnibus/config.rb, line 643 def set_or_return(key, value = NULL, default = NULL, &block) instance_variable = :"@#{key}" if null?(value) if instance_variable_defined?(instance_variable) instance_variable_get(instance_variable) else if block instance_eval(&block) else null?(default) ? nil : default end end else instance_variable_set(instance_variable, value) end end