class Excursion::Configuration
Constants
- DEFAULT_CONFIGURATION_OPTIONS
Public Class Methods
new()
click to toggle source
Calls superclass method
# File lib/excursion/configuration.rb, line 86 def initialize DEFAULT_CONFIGURATION_OPTIONS.each do |key,val| instance_variable_set "@#{key.to_s}", val end save_state super end
Public Instance Methods
changed()
click to toggle source
Returns a hash of all the changed keys and values after being reconfigured
# File lib/excursion/configuration.rb, line 38 def changed @changed = {} to_hash.each { |key,val| @changed[key] = [@saved_state[key], val] if @saved_state[key] != val } @changed end
changed?(key)
click to toggle source
Check whether a key was changed after being reconfigured
# File lib/excursion/configuration.rb, line 45 def changed?(key) changed.has_key?(key) end
configure(args={}, &block)
click to toggle source
Pass arguments and/or a block to configure the available options
# File lib/excursion/configuration.rb, line 50 def configure(args={}, &block) save_state configure_with_args args configure_with_block &block if block_given? self end
configure_with_args(args)
click to toggle source
Accepts arguments which are used to configure available options
# File lib/excursion/configuration.rb, line 58 def configure_with_args(args) args.select { |k,v| DEFAULT_CONFIGURATION_OPTIONS.keys.include?(k) }.each do |key,val| instance_variable_set "@#{key.to_s}", val end end
configure_with_block(&block)
click to toggle source
Accepts a block which is used to configure available options
# File lib/excursion/configuration.rb, line 65 def configure_with_block(&block) self.instance_eval(&block) if block_given? end
method_missing(meth, *args)
click to toggle source
DEFAULT_CONFIGURATION_OPTIONS.keys.each do |key|
define_method "#{key.to_s}=" do |val| @changed[key] = [send(key), val] instance_variable_set "@#{key.to_s}", val end
end
# File lib/excursion/configuration.rb, line 28 def method_missing(meth, *args) if meth.to_s.match(/\A(.*)=\Z/) @changed[$1] = [send($1), *args] instance_variable_set "@#{$1.to_s}", *args else instance_variable_get "@#{meth}" end end
save_state()
click to toggle source
Saves a copy of the current state, to be used later to determine what was changed
# File lib/excursion/configuration.rb, line 70 def save_state @saved_state = clone.to_hash @changed = {} end
to_hash()
click to toggle source
# File lib/excursion/configuration.rb, line 75 def to_hash h = {} DEFAULT_CONFIGURATION_OPTIONS.keys.each do |key| h[key] = instance_variable_get "@#{key.to_s}" end h end
Also aliased as: to_h