Sha256: 539136b0148b869f1544428fc652964e030fb1f9dbe63bf49c0ac5b1bf421446
Contents?: true
Size: 1.87 KB
Versions: 6
Compression:
Stored size: 1.87 KB
Contents
require 'rubygems' require 'chronic' require 'sequel' require 'yaml' require 'sequel/extensions/inflector' require 'Getopt/Declare' require File.join(File.dirname(__FILE__), 'timetrap', 'config') require File.join(File.dirname(__FILE__), 'timetrap', 'helpers') require File.join(File.dirname(__FILE__), 'timetrap', 'cli') DB_NAME = defined?(TEST_MODE) ? nil : Timetrap::Config['database_file'] # connect to database. This will create one if it doesn't exist DB = Sequel.sqlite DB_NAME require File.join(File.dirname(__FILE__), 'timetrap', 'models') Dir["#{File.dirname(__FILE__)}/timetrap/formatters/*.rb"].each do |path| require path end module Timetrap extend self def current_sheet= sheet m = Meta.find_or_create(:key => 'current_sheet') m.value = sheet m.save end def current_sheet unless Meta.find(:key => 'current_sheet') Meta.create(:key => 'current_sheet', :value => 'default') end Meta.find(:key => 'current_sheet').value end def entries sheet = nil Entry.filter(:sheet => sheet).order_by(:start) end def running? !!active_entry end def active_entry Entry.find(:sheet => Timetrap.current_sheet, :end => nil) end def stop time = nil while a = active_entry time ||= Time.now a.end = time a.save end end def start note, time = nil raise AlreadyRunning if running? time ||= Time.now Entry.create(:sheet => Timetrap.current_sheet, :note => note, :start => time).save rescue => e CLI.say e.message end def switch sheet self.current_sheet = sheet end def kill_sheet sheet Entry.filter(:sheet => sheet).destroy end def format format_klass, entries format_klass.new(entries).output end class AlreadyRunning < StandardError def message "Timetrap is already running" end end CLI.args = Getopt::Declare.new(<<-EOF) #{CLI::USAGE} EOF end
Version data entries
6 entries across 6 versions & 1 rubygems
Version | Path |
---|---|
timetrap-1.5.3 | lib/timetrap.rb |
timetrap-1.5.2 | lib/timetrap.rb |
timetrap-1.5.1 | lib/timetrap.rb |
timetrap-1.5.0 | lib/timetrap.rb |
timetrap-1.4.0 | lib/timetrap.rb |
timetrap-1.3.0 | lib/timetrap.rb |