one_inch_punch 0.1.2 → 0.1.3

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/History.txt CHANGED
@@ -1,3 +1,10 @@
1
+ == 0.1.3 2008-09-30
2
+
3
+ * 3 enhancements:
4
+ * Punching in and out can take a time (with now as a default)
5
+ * Punching in and out can take a message (in addition to the auto-generated time-based message)
6
+ * punch command options for in/out time and message
7
+
1
8
  == 0.1.2 2008-08-28
2
9
 
3
10
  * 1 tiny enhancement:
data/bin/punch CHANGED
@@ -29,6 +29,10 @@ BANNER
29
29
  "Restrict command to only after the given time") { |time| OPTIONS[:after] = Time.parse(time) }
30
30
  opts.on('--before [TIME]', String,
31
31
  "Restrict command to only before the given time") { |time| OPTIONS[:before] = Time.parse(time) }
32
+ opts.on('--at [TIME]', '--time [TIME]', String,
33
+ "Use the given time to punch in/out") { |time| OPTIONS[:time] = Time.parse(time) }
34
+ opts.on('-m', '--message [MESSAGE]', String,
35
+ "Add the given log message when punching in/out") { |message| OPTIONS[:message] = message }
32
36
  opts.on("-h", "--help",
33
37
  "Show this help message.") { puts opts; exit }
34
38
  opts.parse!(ARGV)
@@ -54,7 +58,7 @@ commands = {
54
58
  'total' => lambda { |project| puts Punch.total(project, OPTIONS.merge(:format => true)).inspect },
55
59
  'in' => lambda do |project|
56
60
  if project
57
- if Punch.in(project)
61
+ if Punch.in(project, OPTIONS)
58
62
  Punch.write
59
63
  else
60
64
  puts "Already punched in to '#{project}'"
@@ -72,7 +76,7 @@ commands = {
72
76
  end
73
77
  end,
74
78
  'out' => lambda do |project|
75
- if Punch.out(project)
79
+ if Punch.out(project, OPTIONS)
76
80
  Punch.write
77
81
  else
78
82
  message = 'Already punched out of '
data/lib/punch/version.rb CHANGED
@@ -2,7 +2,7 @@ module Punch
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
4
  MINOR = 1
5
- TINY = 2
5
+ TINY = 3
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
data/lib/punch.rb CHANGED
@@ -50,20 +50,23 @@ module Punch
50
50
  status(project) == 'in'
51
51
  end
52
52
 
53
- def in(project)
53
+ def in(project, options = {})
54
54
  return false if in?(project)
55
55
  data[project] ||= []
56
- time = Time.now
56
+ time = time_from_options(options)
57
57
  data[project].push({'in' => time})
58
58
  log(project, "punch in @ #{time.strftime('%Y-%m-%dT%H:%M:%S%z')}")
59
+ log(project, options[:message]) if options[:message]
59
60
  true
60
61
  end
61
62
 
62
- def out(project = nil)
63
+ def out(*args)
64
+ options = args.last.is_a?(Hash) ? args.pop : {}
65
+ project = args.first
63
66
  if project
64
- return false unless do_out_single(project)
67
+ return false unless do_out_single(project, options)
65
68
  else
66
- return false unless data.keys.collect { |project| do_out_single(project) }.any?
69
+ return false unless data.keys.collect { |project| do_out_single(project, options) }.any?
67
70
  end
68
71
  true
69
72
  end
@@ -105,9 +108,10 @@ module Punch
105
108
 
106
109
  private
107
110
 
108
- def do_out_single(project)
111
+ def do_out_single(project, options)
109
112
  return false if out?(project)
110
- time = Time.now
113
+ time = time_from_options(options)
114
+ log(project, options[:message]) if options[:message]
111
115
  log(project, "punch out @ #{time.strftime('%Y-%m-%dT%H:%M:%S%z')}")
112
116
  data[project].last['out'] = time
113
117
  end
@@ -124,5 +128,9 @@ module Punch
124
128
  return total unless options[:format]
125
129
  total.elapsed_time
126
130
  end
131
+
132
+ def time_from_options(options)
133
+ options[:time] || options[:at] || Time.now
134
+ end
127
135
  end
128
136
  end
@@ -156,10 +156,36 @@ describe 'punch command' do
156
156
  end
157
157
 
158
158
  it 'should punch in to the given project' do
159
- Punch.expects(:in).with(@project)
159
+ Punch.expects(:in).with(@project, {})
160
160
  run_command('in', @project)
161
161
  end
162
162
 
163
+ it 'should pass a time if specified on the command line (with --time)' do
164
+ time_option = '2008-08-23 15:39'
165
+ time = Time.local(2008, 8, 23, 15, 39)
166
+ Punch.expects(:in).with(@project, has_entry(:time => time))
167
+ run_command('in', @project, '--time', time_option)
168
+ end
169
+
170
+ it 'should pass a time if specified on the command line (with --at)' do
171
+ time_option = '2008-08-23 15:39'
172
+ time = Time.local(2008, 8, 23, 15, 39)
173
+ Punch.expects(:in).with(@project, has_entry(:time => time))
174
+ run_command('in', @project, '--at', time_option)
175
+ end
176
+
177
+ it 'should pass a message if specified on the command line (with --message)' do
178
+ message = 'About to do some amazing work'
179
+ Punch.expects(:in).with(@project, has_entry(:message => message))
180
+ run_command('in', @project, '--message', message)
181
+ end
182
+
183
+ it 'should pass a message if specified on the command line (with -m)' do
184
+ message = 'About to do some amazing work'
185
+ Punch.expects(:in).with(@project, has_entry(:message => message))
186
+ run_command('in', @project, '-m', message)
187
+ end
188
+
163
189
  describe 'when punched in successfully' do
164
190
  before :each do
165
191
  Punch.stubs(:in).returns(true)
@@ -226,13 +252,67 @@ describe 'punch command' do
226
252
  end
227
253
 
228
254
  it 'should punch out of the given project' do
229
- Punch.expects(:out).with(@project)
255
+ Punch.expects(:out).with(@project, {})
230
256
  run_command('out', @project)
231
257
  end
232
258
 
233
- it 'should punch out of all projects if none given' do
234
- Punch.expects(:out).with(nil)
235
- run_command('out')
259
+ it 'should pass a time if specified on the command line (with --time)' do
260
+ time_option = '2008-08-23 15:39'
261
+ time = Time.local(2008, 8, 23, 15, 39)
262
+ Punch.expects(:out).with(@project, has_entry(:time => time))
263
+ run_command('out', @project, '--time', time_option)
264
+ end
265
+
266
+ it 'should pass a time if specified on the command line (with --at)' do
267
+ time_option = '2008-08-23 15:39'
268
+ time = Time.local(2008, 8, 23, 15, 39)
269
+ Punch.expects(:out).with(@project, has_entry(:time => time))
270
+ run_command('out', @project, '--at', time_option)
271
+ end
272
+
273
+ it 'should pass a message if specified on the command line (with --message)' do
274
+ message = 'Finished doing some stellar work'
275
+ Punch.expects(:out).with(@project, has_entry(:message => message))
276
+ run_command('out', @project, '--message', message)
277
+ end
278
+
279
+ it 'should pass a message if specified on the command line (with -m)' do
280
+ message = 'Finished doing some stellar work'
281
+ Punch.expects(:out).with(@project, has_entry(:message => message))
282
+ run_command('out', @project, '-m', message)
283
+ end
284
+
285
+ describe 'if no project given' do
286
+ it 'should punch out of all projects' do
287
+ Punch.expects(:out).with(nil, {})
288
+ run_command('out')
289
+ end
290
+
291
+ it 'should pass a time if specified on the command line (with --time)' do
292
+ time_option = '2008-08-23 15:39'
293
+ time = Time.local(2008, 8, 23, 15, 39)
294
+ Punch.expects(:out).with(nil, has_entry(:time => time))
295
+ run_command('out', '--time', time_option)
296
+ end
297
+
298
+ it 'should pass a time if specified on the command line (with --at)' do
299
+ time_option = '2008-08-23 15:39'
300
+ time = Time.local(2008, 8, 23, 15, 39)
301
+ Punch.expects(:out).with(nil, has_entry(:time => time))
302
+ run_command('out', '--at', time_option)
303
+ end
304
+
305
+ it 'should pass a message if specified on the command line (with --message)' do
306
+ message = 'Finished doing some stellar work'
307
+ Punch.expects(:out).with(nil, has_entry(:message => message))
308
+ run_command('out', '--message', message)
309
+ end
310
+
311
+ it 'should pass a message if specified on the command line (with -m)' do
312
+ message = 'Finished doing some stellar work'
313
+ Punch.expects(:out).with(nil, has_entry(:message => message))
314
+ run_command('out', '-m', message)
315
+ end
236
316
  end
237
317
 
238
318
  describe 'when punched out successfully' do
data/spec/punch_spec.rb CHANGED
@@ -287,6 +287,10 @@ describe Punch do
287
287
  lambda { Punch.in }.should raise_error(ArgumentError)
288
288
  end
289
289
 
290
+ it 'should accept options' do
291
+ lambda { Punch.in('proj', :time => Time.now) }.should_not raise_error(ArgumentError)
292
+ end
293
+
290
294
  describe 'when the project is already punched in' do
291
295
  before :each do
292
296
  @data = { @project => [ {'in' => @now - 50, 'out' => @now - 25}, {'in' => @now - 5} ] }
@@ -321,6 +325,32 @@ describe Punch do
321
325
  Punch.in(@project)
322
326
  end
323
327
 
328
+ it 'should use a different time if given' do
329
+ time = @now + 50
330
+ Punch.in(@project, :time => time)
331
+ Punch.data[@project].last['in'].should == time
332
+ end
333
+
334
+ it 'should log a message using the given time' do
335
+ time = @now + 75
336
+ time_str = time.strftime('%Y-%m-%dT%H:%M:%S%z')
337
+ Punch.expects(:log).with(@project, "punch in @ #{time_str}")
338
+ Punch.in(@project, :time => time)
339
+ end
340
+
341
+ it 'should log an additional message if given' do
342
+ Punch.stubs(:log) # for the time-based message
343
+ message = 'working on some stuff'
344
+ Punch.expects(:log).with(@project, message)
345
+ Punch.in(@project, :message => message)
346
+ end
347
+
348
+ it "should allow the different time to be specified using :at" do
349
+ time = @now + 50
350
+ Punch.in(@project, :at => time)
351
+ Punch.data[@project].last['in'].should == time
352
+ end
353
+
324
354
  it 'should return true' do
325
355
  Punch.in(@project).should == true
326
356
  end
@@ -352,6 +382,19 @@ describe Punch do
352
382
  Punch.in(@project)
353
383
  end
354
384
 
385
+ it 'should use a different time if given' do
386
+ time = @now + 50
387
+ Punch.in(@project, :time => time)
388
+ Punch.data[@project].last['in'].should == time
389
+ end
390
+
391
+ it 'should log a message using the given time' do
392
+ time = @now + 75
393
+ time_str = time.strftime('%Y-%m-%dT%H:%M:%S%z')
394
+ Punch.expects(:log).with(@project, "punch in @ #{time_str}")
395
+ Punch.in(@project, :time => time)
396
+ end
397
+
355
398
  it 'should return true' do
356
399
  Punch.in(@project).should == true
357
400
  end
@@ -385,6 +428,14 @@ describe Punch do
385
428
  lambda { Punch.out }.should_not raise_error(ArgumentError)
386
429
  end
387
430
 
431
+ it 'should accept a project name and options' do
432
+ lambda { Punch.out('proj', :time => Time.now) }.should_not raise_error(ArgumentError)
433
+ end
434
+
435
+ it 'should accept options without a project name' do
436
+ lambda { Punch.out(:time => Time.now) }.should_not raise_error(ArgumentError)
437
+ end
438
+
388
439
  describe 'when the project is already punched out' do
389
440
  it 'should not change the project data' do
390
441
  old_data = @data.dup
@@ -413,12 +464,38 @@ describe Punch do
413
464
  Punch.data[@project].last['out'].should == @now
414
465
  end
415
466
 
416
- it 'should log a message about punch-in time' do
467
+ it 'should log a message about punch-out time' do
417
468
  time = @now.strftime('%Y-%m-%dT%H:%M:%S%z')
418
469
  Punch.expects(:log).with(@project, "punch out @ #{time}")
419
470
  Punch.out(@project)
420
471
  end
421
472
 
473
+ it 'should use a different time if given' do
474
+ time = @now + 50
475
+ Punch.out(@project, :time => time)
476
+ Punch.data[@project].last['out'].should == time
477
+ end
478
+
479
+ it 'should log a message using the given time' do
480
+ time = @now + 75
481
+ time_str = time.strftime('%Y-%m-%dT%H:%M:%S%z')
482
+ Punch.expects(:log).with(@project, "punch out @ #{time_str}")
483
+ Punch.out(@project, :time => time)
484
+ end
485
+
486
+ it 'should log an additional message if given' do
487
+ Punch.stubs(:log) # for the time-based message
488
+ message = 'finished working on some stuff'
489
+ Punch.expects(:log).with(@project, message)
490
+ Punch.out(@project, :message => message)
491
+ end
492
+
493
+ it "should allow the different time to be specified using :at" do
494
+ time = @now + 50
495
+ Punch.out(@project, :at => time)
496
+ Punch.data[@project].last['out'].should == time
497
+ end
498
+
422
499
  it 'should return true' do
423
500
  Punch.out(@project).should == true
424
501
  end
@@ -449,6 +526,30 @@ describe Punch do
449
526
  Punch.out
450
527
  end
451
528
 
529
+ it 'should use a different time if given' do
530
+ time = @now + 50
531
+ Punch.out(:time => time)
532
+ Punch.data[@projects[0]].last['out'].should == @now - 25
533
+ Punch.data[@projects[1]].last['out'].should == time
534
+ Punch.data[@projects[2]].last['out'].should == time
535
+ end
536
+
537
+ it 'should log messages using the given time' do
538
+ time = @now + 75
539
+ time_str = time.strftime('%Y-%m-%dT%H:%M:%S%z')
540
+ Punch.expects(:log).with(@projects[1], "punch out @ #{time_str}")
541
+ Punch.expects(:log).with(@projects[2], "punch out @ #{time_str}")
542
+ Punch.out(:time => time)
543
+ end
544
+
545
+ it 'should log an additional message if given' do
546
+ Punch.stubs(:log) # for the time-based messages
547
+ message = 'finished working on some stuff'
548
+ Punch.expects(:log).with(@projects[1], message)
549
+ Punch.expects(:log).with(@projects[2], message)
550
+ Punch.out(:message => message)
551
+ end
552
+
452
553
  it 'should return true' do
453
554
  Punch.out.should == true
454
555
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: one_inch_punch
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.2
4
+ version: 0.1.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Yossef Mendelssohn
@@ -9,7 +9,7 @@ autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
11
 
12
- date: 2008-08-28 00:00:00 -05:00
12
+ date: 2008-09-30 00:00:00 -05:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency