class Trinidad::Configuration
Trinidad's (global) configuration instance. Use Trinidad#configure to update and obtain the global instance or access the instance using Trinidad#configuration
Constants
- DEFAULTS
Public Class Methods
merge_options(target, current, deep = true)
click to toggle source
a Hash like deep_merge helper
# File lib/trinidad/configuration.rb, line 114 def self.merge_options(target, current, deep = true) return target unless current target_dup = target.dup current.keys.each do |key| target_dup[key] = if deep && options_like?(target[key]) && options_like?(current[key]) merge_options(target[key], current[key], deep) else current[key] end end target_dup end
new(options = {})
click to toggle source
# File lib/trinidad/configuration.rb, line 51 def initialize(options = {}) @config = DEFAULTS.clone update!(options) end
symbolize_options(options, deep = true)
click to toggle source
a Hash like symbolize helper
# File lib/trinidad/configuration.rb, line 96 def self.symbolize_options(options, deep = true) new_options = options.class.new options.each do |key, value| if deep && value.is_a?(Array) # YAML::Omap is an Array array = new_options[key.to_sym] = value.class.new value.each do |v| array << ( options_like?(v) ? symbolize_options(v, deep) : v ) end elsif deep && options_like?(value) new_options[key.to_sym] = symbolize_options(value, deep) else new_options[key.to_sym] = value end end new_options end
Private Class Methods
options_like?(object)
click to toggle source
# File lib/trinidad/configuration.rb, line 129 def self.options_like?(object) object.is_a?(Hash) || ( object.respond_to?(:keys) && object.respond_to?(:'[]') ) end
Public Instance Methods
[](name)
click to toggle source
# File lib/trinidad/configuration.rb, line 56 def [](name) @config[name.to_sym] end
[]=(name, value)
click to toggle source
# File lib/trinidad/configuration.rb, line 60 def []=(name, value) @config[name.to_sym] = value end
each(&block)
click to toggle source
# File lib/trinidad/configuration.rb, line 73 def each(&block) @config.each(&block) end
has_key?(name)
click to toggle source
# File lib/trinidad/configuration.rb, line 64 def has_key?(name) @config.has_key?(name.to_sym) end
Also aliased as: key?
keys()
click to toggle source
# File lib/trinidad/configuration.rb, line 69 def keys @config.keys end
update!(options)
click to toggle source
# File lib/trinidad/configuration.rb, line 77 def update!(options) options.each do |key, value| self[key] = value.respond_to?(:strip) ? value.strip : value end end