timetrap 1.8.3 → 1.8.4

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
data/README.md CHANGED
@@ -57,13 +57,19 @@ If you make a mistake use the `edit` command.
57
57
 
58
58
  $ # edit the running entry's note
59
59
  $ t edit writing readme
60
- editing entry #42
60
+ Editing running entry
61
61
 
62
62
  You check out with the `out` command.
63
63
 
64
64
  $ t out
65
65
  Checked out of sheet "coding"
66
66
 
67
+ Running `edit` when you're checked out will edit the last sheet you checked out
68
+ of.
69
+
70
+ $ t edit --append "oh and that"
71
+ Editing last entry you checked out of
72
+
67
73
  You can edit entries that aren't running using `edit`'s `--id` or `-i` flag.
68
74
  `t display --ids` (or `t display -v`) will tell you the ids.
69
75
 
@@ -78,7 +84,7 @@ You can edit entries that aren't running using `edit`'s `--id` or `-i` flag.
78
84
 
79
85
  $ # -i43 to edit entry 43
80
86
  $ t e -i43 --end "2010-11-28 13:45"
81
- editing entry #43
87
+ Editing entry with id 43
82
88
 
83
89
  $ t d
84
90
  Timesheet: coding
@@ -264,8 +270,8 @@ Commands
264
270
 
265
271
  **edit**
266
272
  Inserts a note associated with the an entry in the timesheet, or edits the
267
- start or end times. Defaults to the current time although an ``--id`` flag can
268
- be passed with the entry's id (see display.)
273
+ start or end times. Defaults to the current entry, or previously running
274
+ entry. An ``--id`` flag can be passed with the entry's id (see display.)
269
275
 
270
276
  usage: ``t edit [--id ID] [--start TIME] [--end TIME] [--append] [NOTES]``
271
277
 
data/VERSION.yml CHANGED
@@ -1,4 +1,4 @@
1
1
  ---
2
2
  :major: 1
3
3
  :minor: 8
4
- :patch: 3
4
+ :patch: 4
data/lib/timetrap/cli.rb CHANGED
@@ -53,7 +53,8 @@ COMMAND is one of:
53
53
  found in the README included in this
54
54
  distribution.
55
55
 
56
- * edit - Alter an entry's note, start, or end time. Defaults to the active entry.
56
+ * edit - Alter an entry's note, start, or end time. Defaults to the active
57
+ entry. Defaults to the last entry to be checked out of if no entry is active.
57
58
  usage: t edit [--id ID] [--start TIME] [--end TIME] [--append] [NOTES]
58
59
  -i, --id <id:i> Alter entry with id <id> instead of the running entry
59
60
  -s, --start <time:qs> Change the start time to <time>
@@ -198,13 +199,24 @@ COMMAND is one of:
198
199
  end
199
200
 
200
201
  def edit
201
- entry = args['-i'] ? Entry[args['-i']] : Timer.active_entry
202
+ entry = case
203
+ when args['-i']
204
+ warn "Editing entry with id #{args['-i'].inspect}"
205
+ Entry[args['-i']]
206
+ when Timer.active_entry
207
+ warn "Editing running entry"
208
+ Timer.active_entry
209
+ when Timer.last_checkout
210
+ warn "Editing last entry you checked out of"
211
+ Timer.last_checkout
212
+ end
213
+
202
214
  unless entry
203
- warn "can't find entry"
215
+ warn "Can't find entry"
204
216
  return
205
- else
206
- warn "editing entry ##{entry.id.inspect}"
207
217
  end
218
+ warn ""
219
+
208
220
  entry.update :start => args['-s'] if args['-s'] =~ /.+/
209
221
  entry.update :end => args['-e'] if args['-e'] =~ /.+/
210
222
 
@@ -224,6 +236,8 @@ COMMAND is one of:
224
236
  end
225
237
  entry.update :note => note
226
238
  end
239
+
240
+ puts format_entries(entry)
227
241
  end
228
242
 
229
243
  def backend
@@ -289,7 +303,7 @@ COMMAND is one of:
289
303
  if entries == []
290
304
  warn "No entries were selected to display."
291
305
  else
292
- puts load_formatter(args['-f'] || Config['default_formatter']).new(entries).output
306
+ puts format_entries(entries)
293
307
  end
294
308
  end
295
309
 
@@ -385,5 +399,9 @@ COMMAND is one of:
385
399
  $stdin.gets =~ /\Aye?s?\Z/i
386
400
  end
387
401
 
402
+ def format_entries(entries)
403
+ load_formatter(args['-f'] || Config['default_formatter']).new(Array(entries)).output
404
+ end
405
+
388
406
  end
389
407
  end
@@ -83,6 +83,12 @@ module Timetrap
83
83
  Entry.find(:sheet => (sheet || Timer.current_sheet), :end => nil)
84
84
  end
85
85
 
86
+ # the last entry to be checked out of
87
+ def last_checkout
88
+ meta = Meta.find(:key => 'last_checkout_id')
89
+ Entry[meta.value] if meta
90
+ end
91
+
86
92
  def running_entries
87
93
  Entry.filter(:end => nil)
88
94
  end
@@ -103,6 +109,9 @@ module Timetrap
103
109
  time ||= Time.now
104
110
  a.end = time
105
111
  a.save
112
+ meta = Meta.find(:key => 'last_checkout_id') || Meta.create(:key => 'last_checkout_id')
113
+ meta.value = a.id
114
+ meta.save
106
115
  end
107
116
  a
108
117
  end
@@ -188,9 +188,35 @@ describe Timetrap do
188
188
  not_running = Timetrap::Timer.active_entry
189
189
  Timetrap::Timer.stop(Timetrap::Timer.current_sheet)
190
190
  Timetrap::Timer.start "another entry", nil
191
+
192
+ # create a few more entries to ensure we're not falling back on "last
193
+ # checked out of" feature.
194
+ Timetrap::Timer.stop(Timetrap::Timer.current_sheet)
195
+ Timetrap::Timer.start "another entry", nil
196
+
197
+ Timetrap::Timer.stop(Timetrap::Timer.current_sheet)
198
+ Timetrap::Timer.start "another entry", nil
199
+
191
200
  invoke "edit --id #{not_running.id} a new description"
192
201
  not_running.refresh.note.should == 'a new description'
193
202
  end
203
+
204
+ it "should edit the entry last checked out of if none is running" do
205
+ not_running = Timetrap::Timer.active_entry
206
+ Timetrap::Timer.stop(Timetrap::Timer.current_sheet)
207
+ invoke "edit -z 'a new description'"
208
+ not_running.refresh.note.should include 'a new description'
209
+ end
210
+
211
+ it "should edit the entry last checked out of if none is running even if the sheet is changed" do
212
+ not_running = Timetrap::Timer.active_entry
213
+ Timetrap::Timer.stop(Timetrap::Timer.current_sheet)
214
+ invoke "edit -z 'a new description'"
215
+ invoke "sheet another second sheet"
216
+ not_running.refresh.note.should include 'a new description'
217
+ not_running.refresh.sheet.should == 'default'
218
+ Timetrap::Timer.current_sheet.should == 'another second sheet'
219
+ end
194
220
  end
195
221
 
196
222
  describe "backend" do
@@ -989,6 +1015,13 @@ END:VCALENDAR
989
1015
  time.to_i.should == e.refresh.end.to_i
990
1016
  end
991
1017
 
1018
+ it "should track the last entry that was checked out of" do
1019
+ Timetrap::Timer.start 'some work'
1020
+ e = Timetrap::Timer.active_entry
1021
+ Timetrap::Timer.stop Timetrap::Timer.current_sheet
1022
+ Timetrap::Timer.last_checkout.id.should == e.id
1023
+ end
1024
+
992
1025
  end
993
1026
 
994
1027
  describe Timetrap::Helpers do
data/timetrap.gemspec CHANGED
@@ -5,11 +5,11 @@
5
5
 
6
6
  Gem::Specification.new do |s|
7
7
  s.name = "timetrap"
8
- s.version = "1.8.3"
8
+ s.version = "1.8.4"
9
9
 
10
10
  s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
11
11
  s.authors = ["Sam Goldstein"]
12
- s.date = "2012-11-07"
12
+ s.date = "2012-11-17"
13
13
  s.description = "Command line time tracker"
14
14
  s.email = "sgrock@gmail.com"
15
15
  s.executables = ["t"]
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: timetrap
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.8.3
4
+ version: 1.8.4
5
5
  prerelease:
6
6
  platform: ruby
7
7
  authors:
@@ -9,7 +9,7 @@ authors:
9
9
  autorequire:
10
10
  bindir: bin
11
11
  cert_chain: []
12
- date: 2012-11-07 00:00:00.000000000 Z
12
+ date: 2012-11-17 00:00:00.000000000 Z
13
13
  dependencies:
14
14
  - !ruby/object:Gem::Dependency
15
15
  name: sequel