class Terradactyl::ConfigApplication
Constants
- CONFIG_DEFAULTS
Attributes
config_file[R]
terradactyl[R]
Public Class Methods
new(config_file = nil, defaults: nil)
click to toggle source
# File lib/terradactyl/config.rb, line 46 def initialize(config_file = nil, defaults: nil) @config_file = config_file @defaults = load_defaults(defaults) @overlay = load_overlay(config_file) load_config end
Public Instance Methods
reload()
click to toggle source
# File lib/terradactyl/config.rb, line 53 def reload load_config end
to_h()
click to toggle source
# File lib/terradactyl/config.rb, line 57 def to_h @config end
Also aliased as: to_hash
Private Instance Methods
configure_colorization()
click to toggle source
# File lib/terradactyl/config.rb, line 97 def configure_colorization String.disable_colorization = terradactyl.misc.disable_color end
load_config()
click to toggle source
# File lib/terradactyl/config.rb, line 64 def load_config @config = [ @defaults, @overlay ].inject({}) do |memo, obj| memo.deep_merge!(obj, overwrite_arrays: true) Marshal.load(Marshal.dump(memo)) end @terradactyl = structify(@config).terradactyl configure_colorization @terradactyl end
load_defaults(defaults)
click to toggle source
# File lib/terradactyl/config.rb, line 77 def load_defaults(defaults) defaults || YAML.safe_load(CONFIG_DEFAULTS) end
load_empty()
click to toggle source
# File lib/terradactyl/config.rb, line 87 def load_empty { 'terradactyl' => {} } end
load_overlay(config_file)
click to toggle source
# File lib/terradactyl/config.rb, line 81 def load_overlay(config_file) YAML.load_file(config_file.to_s) rescue Errno::ENOENT load_empty end
method_missing(sym, *args, &block)
click to toggle source
Calls superclass method
# File lib/terradactyl/config.rb, line 101 def method_missing(sym, *args, &block) terradactyl.send(sym.to_sym, *args, &block) rescue NameError super end
respond_to_missing?(sym, *args)
click to toggle source
Calls superclass method
# File lib/terradactyl/config.rb, line 107 def respond_to_missing?(sym, *args) terradactyl.respond_to?(sym) || super end
structify(hash)
click to toggle source
# File lib/terradactyl/config.rb, line 91 def structify(hash) OpenStruct.new(hash.each_with_object({}) do |(key, val), memo| memo[key] = val.is_a?(Hash) ? structify(val) : val end) end