Module: Timetrap::Config

Extended by:
Config
Included in:
Config
Defined in:
lib/timetrap/config.rb

Constant Summary collapse

PATH =
ENV['TIMETRAP_CONFIG_FILE'] || File.join(ENV['HOME'], '.timetrap.yml')

Instance Method Summary collapse

Instance Method Details

#[](key) ⇒ Object



23
24
25
26
27
28
29
30
# File 'lib/timetrap/config.rb', line 23

def [](key)
  overrides = File.exist?(PATH) ? YAML.load(File.read(PATH)) : {}
  defaults.merge(overrides)[key]
rescue => e
  warn "invalid config file"
  warn e.message
  defaults[key]
end

#configure!Object



32
33
34
35
36
37
38
39
40
41
# File 'lib/timetrap/config.rb', line 32

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

#defaultsObject

Application defaults.

These are written to a config file by invoking: t configure



12
13
14
15
16
17
18
19
20
21
# File 'lib/timetrap/config.rb', line 12

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' => ' '
  }
end