Sha256: 8dfd8f220d3adc4601c1471db1a598856e8c2b52233517c2740736f18424b2df
Contents?: true
Size: 1.76 KB
Versions: 2
Compression:
Stored size: 1.76 KB
Contents
module Timetrap module Config extend self PATH = ENV['TIMETRAP_CONFIG_FILE'] || File.join(ENV['HOME'], '.timetrap.yml') # Application defaults. # # These are written to a config file by invoking: # <code> # t configure # </code> def defaults { # Path to the sqlite db 'database_file' => "#{ENV['HOME']}/.timetrap.db", # Unit of time for rounding (-r) in seconds 'round_in_seconds' => 900, # delimiter used when appending notes with `t edit --append` 'append_notes_delimiter' => ' ', # an array of directories to search for user defined fomatter classes 'formatter_search_paths' => [ "#{ENV['HOME']}/.timetrap/formatters" ], # formatter to use when display is invoked without a --format option 'default_formatter' => 'text', # the default command to when you run `t`. default to printing usage. 'default_command' => nil, # only allow one running entry at a time. # automatically check out of any running tasks when checking in. 'auto_checkout' => false, # interactively prompt for a note if one isn't passed when checking in. 'require_note' => false } end def [](key) overrides = File.exist?(PATH) ? YAML.load(erb_render(File.read(PATH))) : {} defaults.merge(overrides)[key] rescue => e warn "invalid config file" warn e.message defaults[key] end def erb_render(content) ERB.new(content).result end def configure! 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 end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
timetrap-1.8.13 | lib/timetrap/config.rb |
timetrap-1.8.12 | lib/timetrap/config.rb |