class Todone::Config
Public Class Methods
load_config(dir)
click to toggle source
@see Todone::Consts:CONFIG_FILE @param [String] dir The directory to look in for the file specified by {Todone::Consts::CONFIG_FILE} @return [Todone::Config] The populated {Config} instance
# File lib/todone/config.rb, line 21 def load_config dir require 'yaml' data = YAML.load(File.open(File.join(dir, Todone::Consts::CONFIG_FILE)).read) Todone::Config.new data end
new(data={})
click to toggle source
# File lib/todone/config.rb, line 34 def initialize(data={}) @data = {} update!(data) end
Public Instance Methods
[](key)
click to toggle source
# File lib/todone/config.rb, line 45 def [](key) @data[key.to_sym] end
[]=(key, value)
click to toggle source
# File lib/todone/config.rb, line 49 def []=(key, value) if value.class == Hash @data[key.to_sym] = Config.new(value) else @data[key.to_sym] = value end end
method_missing(sym, *args)
click to toggle source
# File lib/todone/config.rb, line 65 def method_missing(sym, *args) if sym.to_s =~ /(.+)=$/ self[$1] = args.first else self[sym] end end
save(dir)
click to toggle source
# File lib/todone/config.rb, line 28 def save dir File.open(File.join(dir, Todone::Consts::CONFIG_FILE), 'w') do |f| f.write( @data.to_hash.to_yaml ) end end
to_hash()
click to toggle source
# File lib/todone/config.rb, line 57 def to_hash hash = {} @data.each do |key,value| hash[key] = value.class == Config ? value.to_hash : value end hash end
update!(data)
click to toggle source
# File lib/todone/config.rb, line 39 def update!(data) data.each do |key, value| self[key] = value end end