module Pomato::Paths

Public Instance Methods

add_job(job) click to toggle source
# File lib/pomato/paths.rb, line 45
def add_job(job)
  job[:id] = SecureRandom.uuid
  history "#{job[:id]} add #{job[:start]} #{job[:time]} #{job[:name]}"
  dump_job job
end
append_to(path, content) click to toggle source
# File lib/pomato/paths.rb, line 69
def append_to(path, content)
  File.open(path, 'a') { |f| f.puts content }
end
config() click to toggle source
# File lib/pomato/paths.rb, line 13
def config
  load_yaml path_to 'config'
end
config=(data) click to toggle source
# File lib/pomato/paths.rb, line 17
def config=(data)
  dump_yaml path_to('config'), data
end
destroy_job(job) click to toggle source
# File lib/pomato/paths.rb, line 61
def destroy_job(job)
  File.delete File.join(home('jobs'), job[:id])
end
dump_job(job) click to toggle source
# File lib/pomato/paths.rb, line 41
def dump_job(job)
  dump_yaml(File.join(home('jobs'), job[:id]), job)
end
dump_yaml(path, data) click to toggle source
# File lib/pomato/paths.rb, line 73
def dump_yaml(path, data)
  File.open(path, 'w') { |f| YAML.dump(data, f) }
end
finish_job(job) click to toggle source
# File lib/pomato/paths.rb, line 56
def finish_job(job)
  history "#{job[:id]} finish #{job[:start]} #{job[:time]} #{job[:name]}"
  destroy_job job
end
history(message) click to toggle source
# File lib/pomato/paths.rb, line 25
def history(message)
  append_to path_to('history'), "#{now} #{message}"
end
history_items() click to toggle source
# File lib/pomato/paths.rb, line 29
def history_items
  File.exist?(path_to('history')) ? File.readlines(path_to('history')) : []
end
home(*paths) click to toggle source
# File lib/pomato/paths.rb, line 65
def home(*paths)
  (File.join(File.expand_path('~'),'/.pomato',*paths)).tap {|path| mkdir_p path }
end
jobs() click to toggle source
# File lib/pomato/paths.rb, line 37
def jobs
  Dir["#{home('jobs')}/*"].map {|p| load_yaml(p) }
end
load_yaml(path) click to toggle source
# File lib/pomato/paths.rb, line 77
def load_yaml(path)
  File.exist?(path) ? YAML.load_file(path) : {}
end
now() click to toggle source
# File lib/pomato/paths.rb, line 9
def now
  @now ||= Time.now.to_i
end
path_to(name) click to toggle source
# File lib/pomato/paths.rb, line 33
def path_to(name)
  File.expand_path(File.join(home, name))
end
play_alert() click to toggle source
# File lib/pomato/paths.rb, line 21
def play_alert
  `afplay #{config[:track]}`
end
stop_job(job) click to toggle source
# File lib/pomato/paths.rb, line 51
def stop_job(job)
  history "#{job[:id]} stop #{job[:start]} #{job[:time]} #{job[:name]}"
  destroy_job job
end