Class: Cloudcover::Config
- Inherits:
-
Object
- Object
- Cloudcover::Config
- Extended by:
- PrivateAttrAccessor
- Defined in:
- lib/cloudcover/config.rb
Constant Summary collapse
- CONFIG_DEFAULTS =
{}
- MissingConfig =
Class.new(StandardError)
Class Method Summary collapse
- .config ⇒ Object
- .data ⇒ Object
- .default_value(key) ⇒ Object
- .load(path) ⇒ Object
- .load_config(file) ⇒ Object
- .method_missing(method, args = false) ⇒ Object
- .set_config_options(opts = {}) ⇒ Object
-
.symbolize_keys(hash) ⇒ Object
We want all ouf our YAML loaded keys to be symbols taken from devblog.avdi.org/2009/07/14/recursively-symbolize-keys/.
Methods included from PrivateAttrAccessor
Class Method Details
.config ⇒ Object
36 37 38 |
# File 'lib/cloudcover/config.rb', line 36 def config CONFIG_DEFAULTS.merge data end |
.data ⇒ Object
50 51 52 |
# File 'lib/cloudcover/config.rb', line 50 def data self.config_data ||= {} end |
.default_value(key) ⇒ Object
55 56 57 |
# File 'lib/cloudcover/config.rb', line 55 def default_value(key) CONFIG_DEFAULTS[key.to_sym] end |
.load(path) ⇒ Object
40 41 42 43 |
# File 'lib/cloudcover/config.rb', line 40 def load(path) load_config(path) config end |
.load_config(file) ⇒ Object
67 68 69 70 71 |
# File 'lib/cloudcover/config.rb', line 67 def load_config(file) Output.say_debug("Loading the config file from #{file}") raise MissingConfig, "Missing configuration file: #{file} Run 'cloudcover help'" unless File.exist?(file) self.config_data = symbolize_keys(YAML.load_file(file)) rescue {} end |
.method_missing(method, args = false) ⇒ Object
60 61 62 63 64 |
# File 'lib/cloudcover/config.rb', line 60 def method_missing(method, args=false) return data[method] if data[method] return default_value(method) if default_value(method) nil end |
.set_config_options(opts = {}) ⇒ Object
45 46 47 48 |
# File 'lib/cloudcover/config.rb', line 45 def (opts = {}) data.merge! opts config end |
.symbolize_keys(hash) ⇒ Object
We want all ouf our YAML loaded keys to be symbols taken from devblog.avdi.org/2009/07/14/recursively-symbolize-keys/
76 77 78 79 80 81 82 83 84 85 86 87 88 89 |
# File 'lib/cloudcover/config.rb', line 76 def symbolize_keys(hash) hash.inject({}){|result, (key, value)| new_key = case key when String then key.to_sym else key end new_value = case value when Hash then symbolize_keys(value) else value end result[new_key] = new_value result } end |