diff options
Diffstat (limited to 'lib')
| -rw-r--r-- | lib/hcl/commands.rb | 8 | ||||
| -rw-r--r-- | lib/hcl/day_entry.rb | 4 | ||||
| -rw-r--r-- | lib/hcl/task.rb | 8 | ||||
| -rw-r--r-- | lib/hcl/timesheet_resource.rb | 17 |
4 files changed, 10 insertions, 27 deletions
diff --git a/lib/hcl/commands.rb b/lib/hcl/commands.rb index e2dccb1..98daff5 100644 --- a/lib/hcl/commands.rb +++ b/lib/hcl/commands.rb @@ -11,10 +11,10 @@ module HCl end def tasks project_code=nil - tasks = Task.get_all + tasks = Task.all if tasks.empty? # cache tasks - DayEntry.get_all - tasks = Task.get_all + DayEntry.all + tasks = Task.all end tasks.select! {|t| t.project.code == project_code } if project_code if tasks.empty? @@ -127,7 +127,7 @@ module HCl date = args.empty? ? nil : Chronic.parse(args.join(' ')) total_hours = 0.0 result = '' - DayEntry.get_all(date).each do |day| + DayEntry.all(date).each do |day| running = day.running? ? '(running) ' : '' columns = HighLine::SystemExtensions.terminal_size[0] rescue 80 result << "\t#{day.formatted_hours}\t#{running}#{day.project}: #{day.notes.lines.to_a.last}\n"[0..columns-1] diff --git a/lib/hcl/day_entry.rb b/lib/hcl/day_entry.rb index c245b5a..645bb3d 100644 --- a/lib/hcl/day_entry.rb +++ b/lib/hcl/day_entry.rb @@ -4,7 +4,7 @@ module HCl # Get the time sheet entries for a given day. If no date is provided # defaults to today. - def self.get_all date = nil + def self.all date = nil url = date.nil? ? 'daily' : "daily/#{date.strftime '%j/%Y'}" doc = Net.get url Task.cache_tasks_hash doc @@ -37,7 +37,7 @@ module HCl # If I don't include hours it gets reset. # This doens't appear to be the case for task and project. (self.notes << "\n#{new_notes}").lstrip! - DayEntry.post "daily/update/#{id}", notes:notes, hours:hours + Net.post "daily/update/#{id}", notes:notes, hours:hours end def self.with_timer date=nil diff --git a/lib/hcl/task.rb b/lib/hcl/task.rb index 8c36860..e1d5b58 100644 --- a/lib/hcl/task.rb +++ b/lib/hcl/task.rb @@ -22,7 +22,7 @@ module HCl File.join(HCl::App::HCL_DIR, 'cache') end - def self.get_all + def self.all tasks = File.exists?(cache_file) ? YAML.load(File.read(cache_file)) : [] tasks = tasks.sort do |a,b| r = a.project.client <=> b.project.client @@ -34,7 +34,7 @@ module HCl end def self.find project_id, id - get_all.detect do |t| + all.detect do |t| t.project.id.to_i == project_id.to_i && t.id.to_i == id.to_i end end @@ -50,7 +50,7 @@ module HCl def add opts notes = opts[:note] starting_time = opts[:starting_time] || 0 - DayEntry.post("daily/add", { + DayEntry.new Net.post("daily/add", { notes: notes, hours: starting_time, project_id: project.id, @@ -64,7 +64,7 @@ module HCl if day.running? day else - DayEntry.get("daily/timer/#{day.id}") + DayEntry.new Net.get("daily/timer/#{day.id}") end end end diff --git a/lib/hcl/timesheet_resource.rb b/lib/hcl/timesheet_resource.rb index dcc6b72..28e5378 100644 --- a/lib/hcl/timesheet_resource.rb +++ b/lib/hcl/timesheet_resource.rb @@ -15,22 +15,5 @@ module HCl def respond_to? method (@data && @data.key?(method.to_sym)) || super end - - class << self - def post *args - new Net.post *args - end - def get *args - new Net.get *args - end - def get_all *args - Net.get(*args)[collection_key].map {|o| new o } - end - - def collection_key - @collection_key ||= - self.name.split("::").last.split(/(?=[A-Z])/).map(&:downcase).join('_').to_sym - end - end end end |
