class Octopusci::ConfigStore
Public Class Methods
new()
click to toggle source
# File lib/octopusci/config.rb, line 7 def initialize reset() end
Public Instance Methods
[](key_name)
click to toggle source
allow options to be accessed as if this object is a Hash.
# File lib/octopusci/config.rb, line 31 def [](key_name) if !@options.has_key?(key_name.to_s()) raise MissingConfigField, "'#{key_name}' is NOT defined as a config field." end return @options[key_name.to_s()] end
[]=(key_name, value)
click to toggle source
allow options to be set as if this object is a Hash.
# File lib/octopusci/config.rb, line 39 def []=(key_name, value) @options[key_name.to_s()] = value end
after_load(&block)
click to toggle source
# File lib/octopusci/config.rb, line 59 def after_load(&block) if block @after_load = block elsif @after_load @after_load.call end end
has_key?(key_name)
click to toggle source
# File lib/octopusci/config.rb, line 43 def has_key?(key_name) return @options.has_key?(key_name) end
load(yaml_file = nil) { |self| ... }
click to toggle source
# File lib/octopusci/config.rb, line 19 def load(yaml_file = nil, &block) load_yaml(yaml_file) if !yaml_file.nil? yield self if block after_load() end
method_missing(key_name, *args)
click to toggle source
allow options to be read and set using method calls. This capability is primarily for allowing the configuration to be defined through a block passed to the configure() function from an initializer or similar file.
# File lib/octopusci/config.rb, line 50 def method_missing(key_name, *args) key_name_str = key_name.to_s() if key_name_str =~ /=$/ then self[key_name_str.chop()] = args[0] else return self[key_name_str] end end
options()
click to toggle source
# File lib/octopusci/config.rb, line 15 def options @options end
reload(yaml_file = nil, &block)
click to toggle source
# File lib/octopusci/config.rb, line 25 def reload(yaml_file = nil, &block) reset() load(yaml_file, &block) end
reset()
click to toggle source
# File lib/octopusci/config.rb, line 11 def reset @options = {} end
Private Instance Methods
load_yaml(yaml_file)
click to toggle source
read the configuration values into the object from a YML file.
# File lib/octopusci/config.rb, line 70 def load_yaml(yaml_file) @options.merge!(YAML.load_file(yaml_file)) end