module Todo::Config
The module that contains the methods relevant to configurations and custom configuration in config.yml
similar to Sam Goldstein's config.rb for timetrap @see github.com/samg/timetrap/
Constants
- PATH
The path to the the config file
Public Instance Methods
[](key)
click to toggle source
Overloading [] operator
Accessor for values in the config
@param [Symbol] key the key in the config hash @return [Object] the value associated with that key
# File lib/to-do/config.rb, line 38 def [] key fileval = YAML.load_file PATH defaults.merge(fileval)[key] end
[]=(key, value)
click to toggle source
Overloading []= operator
Setter for values in the Config
hash
@param [Symbol] key the key you are setting a value for @param [Object] value the value you associated with the key
# File lib/to-do/config.rb, line 49 def []= key, value fileval = YAML.load_file PATH configs = defaults.merge(fileval) configs[key] = value File.open(PATH, 'w') do |fh| fh.puts(configs.to_yaml) end end
defaults()
click to toggle source
Default config key value pairs
@return [Hash<Symbol,Object>] the default configurations in a hash
# File lib/to-do/config.rb, line 17 def defaults { # the location of all all your list yaml files :lists_directory => File.join(ENV["HOME"],".to-do","lists"), # a sqlite3 databse that contains all of the tasks :task_database => File.join(ENV["HOME"], ".to-do", "to-do.sqlite"), # the current working list :working_list_name => "My New List", # default width for formatting :width => 50, # default color scheme options :color => "light" } end
write()
click to toggle source
Writes the configs to the file config.yml
# File lib/to-do/config.rb, line 59 def write configs = if File.exist? PATH defaults.merge(YAML.load_file PATH) else defaults end File.open(PATH, 'w') do |fh| fh.puts(configs.to_yaml) end end