one_inch_punch 0.0.3 → 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +10 -0
- data/Manifest.txt +2 -0
- data/README.txt +11 -1
- data/bin/punch +79 -0
- data/lib/punch/version.rb +2 -2
- data/spec/punch_command_spec.rb +392 -0
- metadata +6 -4
data/History.txt
CHANGED
data/Manifest.txt
CHANGED
@@ -3,6 +3,7 @@ License.txt
|
|
3
3
|
Manifest.txt
|
4
4
|
README.txt
|
5
5
|
Rakefile
|
6
|
+
bin/punch
|
6
7
|
config/hoe.rb
|
7
8
|
config/requirements.rb
|
8
9
|
lib/punch.rb
|
@@ -11,6 +12,7 @@ script/console
|
|
11
12
|
script/destroy
|
12
13
|
script/generate
|
13
14
|
setup.rb
|
15
|
+
spec/punch_command_spec.rb
|
14
16
|
spec/punch_spec.rb
|
15
17
|
spec/spec.opts
|
16
18
|
spec/spec_helper.rb
|
data/README.txt
CHANGED
@@ -17,8 +17,10 @@ One-inch punch: Smaller, more effective
|
|
17
17
|
* Can delete a project
|
18
18
|
* Can list project data
|
19
19
|
* Can give total time for a project
|
20
|
+
* Can be used command-line
|
20
21
|
|
21
|
-
*
|
22
|
+
* Command-line does not give access to the list operation
|
23
|
+
* Command-line output is ugly
|
22
24
|
* More, since this is unfinished
|
23
25
|
|
24
26
|
== SYNOPSIS:
|
@@ -33,6 +35,13 @@ One-inch punch: Smaller, more effective
|
|
33
35
|
Punch.out('my project')
|
34
36
|
Punch.out?('my project') # => true
|
35
37
|
Punch.write
|
38
|
+
|
39
|
+
or!
|
40
|
+
|
41
|
+
$ punch in proj
|
42
|
+
$ echo 'working, really'
|
43
|
+
$ punch out proj
|
44
|
+
$ punch status
|
36
45
|
|
37
46
|
== REQUIREMENTS:
|
38
47
|
|
@@ -47,4 +56,5 @@ One-inch punch: Smaller, more effective
|
|
47
56
|
|
48
57
|
* Ara T. Howard, for making punch in the first place
|
49
58
|
* Kevin Barnes, for the name suggestion
|
59
|
+
* Bruce Lee, for having been a bad-ass
|
50
60
|
* The Kool-Aid Man, for busting through my wall. Oh yeah!
|
data/bin/punch
ADDED
@@ -0,0 +1,79 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
#
|
3
|
+
# Created on 2008-8-25.
|
4
|
+
# Copyright (c) 2008. All rights reserved.
|
5
|
+
|
6
|
+
begin
|
7
|
+
require 'rubygems'
|
8
|
+
rescue LoadError
|
9
|
+
# no rubygems to load, so we fail silently
|
10
|
+
end
|
11
|
+
|
12
|
+
require 'punch'
|
13
|
+
require 'optparse'
|
14
|
+
require 'time'
|
15
|
+
|
16
|
+
OPTIONS = {}
|
17
|
+
MANDATORY_OPTIONS = %w[]
|
18
|
+
|
19
|
+
parser = OptionParser.new do |opts|
|
20
|
+
opts.banner = <<BANNER
|
21
|
+
This application is wonderful because...
|
22
|
+
|
23
|
+
Usage: #{File.basename($0)} [options]
|
24
|
+
|
25
|
+
Options are:
|
26
|
+
BANNER
|
27
|
+
opts.separator ''
|
28
|
+
opts.on('-v', '--version',
|
29
|
+
"Show the #{File.basename($0)} version number and exit") { require 'punch/version'; puts "#{File.basename($0)} #{Punch::VERSION::STRING}"; exit }
|
30
|
+
opts.on('--after [TIME]', String,
|
31
|
+
"Restrict command to only after the given time") { |time| OPTIONS[:after] = Time.parse(time) }
|
32
|
+
opts.on('--before [TIME]', String,
|
33
|
+
"Restrict command to only before the given time") { |time| OPTIONS[:before] = Time.parse(time) }
|
34
|
+
opts.on("-h", "--help",
|
35
|
+
"Show this help message.") { puts opts; exit }
|
36
|
+
opts.parse!(ARGV)
|
37
|
+
|
38
|
+
if MANDATORY_OPTIONS && MANDATORY_OPTIONS.find { |option| OPTIONS[option.to_sym].nil? }
|
39
|
+
puts opts; exit
|
40
|
+
end
|
41
|
+
end
|
42
|
+
|
43
|
+
command = ARGV[0]
|
44
|
+
|
45
|
+
unless command
|
46
|
+
puts "Usage: #{File.basename($0)} [command] <project>"
|
47
|
+
exit
|
48
|
+
end
|
49
|
+
|
50
|
+
project = ARGV[1]
|
51
|
+
|
52
|
+
Punch.load
|
53
|
+
case command
|
54
|
+
when 'status'
|
55
|
+
puts Punch.status(project).inspect
|
56
|
+
when 'total'
|
57
|
+
puts Punch.total(project, OPTIONS).inspect
|
58
|
+
when 'in', 'delete'
|
59
|
+
if project
|
60
|
+
Punch.write if result = Punch.send(command, project)
|
61
|
+
puts result.inspect
|
62
|
+
else
|
63
|
+
puts "Project required"
|
64
|
+
end
|
65
|
+
when 'out'
|
66
|
+
Punch.write if result = Punch.out(project)
|
67
|
+
puts result.inspect
|
68
|
+
when 'log'
|
69
|
+
if project
|
70
|
+
if message = ARGV[2]
|
71
|
+
Punch.write if result = Punch.log(project, message)
|
72
|
+
puts result.inspect
|
73
|
+
else
|
74
|
+
puts "Message required"
|
75
|
+
end
|
76
|
+
else
|
77
|
+
puts "Project required"
|
78
|
+
end
|
79
|
+
end
|
data/lib/punch/version.rb
CHANGED
@@ -0,0 +1,392 @@
|
|
1
|
+
require File.dirname(__FILE__) + '/spec_helper.rb'
|
2
|
+
|
3
|
+
describe 'punch command' do
|
4
|
+
def run_command(*args)
|
5
|
+
Object.const_set(:ARGV, args)
|
6
|
+
begin
|
7
|
+
eval File.read(File.join(File.dirname(__FILE__), *%w[.. bin punch]))
|
8
|
+
rescue SystemExit
|
9
|
+
end
|
10
|
+
end
|
11
|
+
|
12
|
+
before :each do
|
13
|
+
[:ARGV, :OPTIONS, :MANDATORY_OPTIONS].each do |const|
|
14
|
+
Object.send(:remove_const, const) if Object.const_defined?(const)
|
15
|
+
end
|
16
|
+
|
17
|
+
self.stubs(:puts)
|
18
|
+
|
19
|
+
Punch.stubs(:load)
|
20
|
+
@test = states('test').starts_as('setup')
|
21
|
+
Punch.stubs(:write).when(@test.is('setup'))
|
22
|
+
@project = 'myproj'
|
23
|
+
end
|
24
|
+
|
25
|
+
it 'should exist' do
|
26
|
+
lambda { run_command }.should_not raise_error(Errno::ENOENT)
|
27
|
+
end
|
28
|
+
|
29
|
+
it 'should require a command' do
|
30
|
+
self.expects(:puts).with(regexp_matches(/usage.+command/i))
|
31
|
+
run_command
|
32
|
+
end
|
33
|
+
|
34
|
+
describe "when the command is 'total'" do
|
35
|
+
before :each do
|
36
|
+
Punch.stubs(:total)
|
37
|
+
end
|
38
|
+
|
39
|
+
it 'should load punch data' do
|
40
|
+
Punch.expects(:load)
|
41
|
+
run_command('total', @project)
|
42
|
+
end
|
43
|
+
|
44
|
+
it 'should get the total for the requested project' do
|
45
|
+
Punch.expects(:total).with(@project, anything)
|
46
|
+
run_command('total', @project)
|
47
|
+
end
|
48
|
+
|
49
|
+
it 'should get the total for all projects if none given' do
|
50
|
+
Punch.expects(:total).with(nil, anything)
|
51
|
+
run_command('total')
|
52
|
+
end
|
53
|
+
|
54
|
+
it 'should output the total' do
|
55
|
+
result = 'total data'
|
56
|
+
Punch.stubs(:total).returns(result)
|
57
|
+
self.expects(:puts).with(result.inspect)
|
58
|
+
run_command('total')
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should not write the data' do
|
62
|
+
@test.become('test')
|
63
|
+
Punch.expects(:write).never.when(@test.is('test'))
|
64
|
+
run_command('total')
|
65
|
+
end
|
66
|
+
|
67
|
+
describe 'when options specified' do
|
68
|
+
it "should pass on an 'after' time option given by --after" do
|
69
|
+
time_option = '2008-08-26 09:47'
|
70
|
+
time = Time.local(2008, 8, 26, 9, 47)
|
71
|
+
Punch.expects(:total).with(@project, has_entry(:after => time))
|
72
|
+
run_command('total', @project, '--after', time_option)
|
73
|
+
end
|
74
|
+
|
75
|
+
it "should pass on a 'before' time option given by --before" do
|
76
|
+
time_option = '2008-08-23 15:39'
|
77
|
+
time = Time.local(2008, 8, 23, 15, 39)
|
78
|
+
Punch.expects(:total).with(@project, has_entry(:before => time))
|
79
|
+
run_command('total', @project, '--before', time_option)
|
80
|
+
end
|
81
|
+
|
82
|
+
it 'should handle a time option given as a date' do
|
83
|
+
time_option = '2008-08-23'
|
84
|
+
time = Time.local(2008, 8, 23)
|
85
|
+
Punch.expects(:total).with(@project, has_entry(:before => time))
|
86
|
+
run_command('total', @project, '--before', time_option)
|
87
|
+
end
|
88
|
+
|
89
|
+
it 'should accept time options if no project given' do
|
90
|
+
time_option = '2008-08-26 09:47'
|
91
|
+
time = Time.local(2008, 8, 26, 9, 47)
|
92
|
+
Punch.expects(:total).with(nil, has_entry(:before => time))
|
93
|
+
run_command('total', '--before', time_option)
|
94
|
+
end
|
95
|
+
end
|
96
|
+
|
97
|
+
it 'should pass no options if none specified' do
|
98
|
+
Punch.expects(:total).with(@project, {})
|
99
|
+
run_command('total', @project)
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
describe "when the command is 'status'" do
|
104
|
+
before :each do
|
105
|
+
Punch.stubs(:status)
|
106
|
+
end
|
107
|
+
|
108
|
+
it 'should load punch data' do
|
109
|
+
Punch.expects(:load)
|
110
|
+
run_command('status', @project)
|
111
|
+
end
|
112
|
+
|
113
|
+
it 'should get the status for the requested project' do
|
114
|
+
Punch.expects(:status).with(@project)
|
115
|
+
run_command('status', @project)
|
116
|
+
end
|
117
|
+
|
118
|
+
it 'should get the status for all projects if none given' do
|
119
|
+
Punch.expects(:status).with(nil)
|
120
|
+
run_command('status')
|
121
|
+
end
|
122
|
+
|
123
|
+
it 'should output the status' do
|
124
|
+
result = 'status data'
|
125
|
+
Punch.stubs(:status).returns(result)
|
126
|
+
self.expects(:puts).with(result.inspect)
|
127
|
+
run_command('status')
|
128
|
+
end
|
129
|
+
|
130
|
+
it 'should not write the data' do
|
131
|
+
@test.become('test')
|
132
|
+
Punch.expects(:write).never.when(@test.is('test'))
|
133
|
+
run_command('status')
|
134
|
+
end
|
135
|
+
end
|
136
|
+
|
137
|
+
describe "when the command is 'in'" do
|
138
|
+
before :each do
|
139
|
+
Punch.stubs(:in).when(@test.is('setup'))
|
140
|
+
end
|
141
|
+
|
142
|
+
it 'should load punch data' do
|
143
|
+
Punch.expects(:load)
|
144
|
+
run_command('in', @project)
|
145
|
+
end
|
146
|
+
|
147
|
+
it 'should punch in to the given project' do
|
148
|
+
@test.become('test')
|
149
|
+
Punch.stubs(:write)
|
150
|
+
Punch.expects(:in).with(@project).when(@test.is('test'))
|
151
|
+
run_command('in', @project)
|
152
|
+
end
|
153
|
+
|
154
|
+
it 'should output the result' do
|
155
|
+
result = 'result'
|
156
|
+
Punch.stubs(:in).returns(result)
|
157
|
+
self.expects(:puts).with(result.inspect)
|
158
|
+
run_command('in', @project)
|
159
|
+
end
|
160
|
+
|
161
|
+
describe 'when punched in successfully' do
|
162
|
+
it 'should write the data' do
|
163
|
+
@test.become('test')
|
164
|
+
Punch.stubs(:in).returns(true)
|
165
|
+
Punch.expects(:write).when(@test.is('test'))
|
166
|
+
run_command('in', @project)
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
describe 'when not punched in successfully' do
|
171
|
+
it 'should not write the data' do
|
172
|
+
@test.become('test')
|
173
|
+
Punch.stubs(:in).returns(false)
|
174
|
+
Punch.expects(:write).never.when(@test.is('test'))
|
175
|
+
run_command('in', @project)
|
176
|
+
end
|
177
|
+
end
|
178
|
+
|
179
|
+
describe 'when no project given' do
|
180
|
+
it 'should display an error message' do
|
181
|
+
self.expects(:puts).with(regexp_matches(/project.+require/i))
|
182
|
+
run_command('in')
|
183
|
+
end
|
184
|
+
|
185
|
+
it 'should not punch in' do
|
186
|
+
@test.become('test')
|
187
|
+
Punch.stubs(:write)
|
188
|
+
Punch.expects(:in).never.when(@test.is('test'))
|
189
|
+
run_command('in')
|
190
|
+
end
|
191
|
+
|
192
|
+
it 'should not write the data' do
|
193
|
+
@test.become('test')
|
194
|
+
Punch.expects(:write).never.when(@test.is('test'))
|
195
|
+
run_command('in')
|
196
|
+
end
|
197
|
+
end
|
198
|
+
end
|
199
|
+
|
200
|
+
describe "when the command is 'out'" do
|
201
|
+
before :each do
|
202
|
+
Punch.stubs(:out)
|
203
|
+
end
|
204
|
+
|
205
|
+
it 'should load punch data' do
|
206
|
+
Punch.expects(:load)
|
207
|
+
run_command('out', @project)
|
208
|
+
end
|
209
|
+
|
210
|
+
it 'should punch out of the given project' do
|
211
|
+
Punch.expects(:out).with(@project)
|
212
|
+
run_command('out', @project)
|
213
|
+
end
|
214
|
+
|
215
|
+
it 'should punch out of all projects if none given' do
|
216
|
+
Punch.expects(:out).with(nil)
|
217
|
+
run_command('out')
|
218
|
+
end
|
219
|
+
|
220
|
+
it 'should output the result' do
|
221
|
+
result = 'result'
|
222
|
+
Punch.stubs(:out).returns(result)
|
223
|
+
self.expects(:puts).with(result.inspect)
|
224
|
+
run_command('out', @project)
|
225
|
+
end
|
226
|
+
|
227
|
+
describe 'when punched out successfully' do
|
228
|
+
it 'should write the data' do
|
229
|
+
@test.become('test')
|
230
|
+
Punch.stubs(:out).returns(true)
|
231
|
+
Punch.expects(:write).when(@test.is('test'))
|
232
|
+
run_command('out', @project)
|
233
|
+
end
|
234
|
+
end
|
235
|
+
|
236
|
+
describe 'when not punched out successfully' do
|
237
|
+
it 'should not write the data' do
|
238
|
+
@test.become('test')
|
239
|
+
Punch.stubs(:out).returns(false)
|
240
|
+
Punch.expects(:write).never.when(@test.is('test'))
|
241
|
+
run_command('out', @project)
|
242
|
+
end
|
243
|
+
end
|
244
|
+
end
|
245
|
+
|
246
|
+
describe "when the command is 'delete'" do
|
247
|
+
before :each do
|
248
|
+
Punch.stubs(:delete).when(@test.is('setup'))
|
249
|
+
end
|
250
|
+
|
251
|
+
it 'should load punch data' do
|
252
|
+
Punch.expects(:load)
|
253
|
+
run_command('delete', @project)
|
254
|
+
end
|
255
|
+
|
256
|
+
it 'should delete the given project' do
|
257
|
+
@test.become('test')
|
258
|
+
Punch.stubs(:write)
|
259
|
+
Punch.expects(:delete).with(@project).when(@test.is('test'))
|
260
|
+
run_command('delete', @project)
|
261
|
+
end
|
262
|
+
|
263
|
+
it 'should output the result' do
|
264
|
+
result = 'result'
|
265
|
+
Punch.stubs(:delete).returns(result)
|
266
|
+
self.expects(:puts).with(result.inspect)
|
267
|
+
run_command('delete', @project)
|
268
|
+
end
|
269
|
+
|
270
|
+
describe 'when deleted successfully' do
|
271
|
+
it 'should write the data' do
|
272
|
+
@test.become('test')
|
273
|
+
Punch.stubs(:delete).returns(true)
|
274
|
+
Punch.expects(:write).when(@test.is('test'))
|
275
|
+
run_command('delete', @project)
|
276
|
+
end
|
277
|
+
end
|
278
|
+
|
279
|
+
describe 'when not deleted successfully' do
|
280
|
+
it 'should not write the data' do
|
281
|
+
@test.become('test')
|
282
|
+
Punch.stubs(:delete).returns(nil)
|
283
|
+
Punch.expects(:write).never.when(@test.is('test'))
|
284
|
+
run_command('delete', @project)
|
285
|
+
end
|
286
|
+
end
|
287
|
+
|
288
|
+
describe 'when no project given' do
|
289
|
+
it 'should display an error message' do
|
290
|
+
self.expects(:puts).with(regexp_matches(/project.+require/i))
|
291
|
+
run_command('delete')
|
292
|
+
end
|
293
|
+
|
294
|
+
it 'should not delete' do
|
295
|
+
@test.become('test')
|
296
|
+
Punch.stubs(:write)
|
297
|
+
Punch.expects(:delete).never.when(@test.is('test'))
|
298
|
+
run_command('delete')
|
299
|
+
end
|
300
|
+
|
301
|
+
it 'should not write the data' do
|
302
|
+
@test.become('test')
|
303
|
+
Punch.expects(:write).never.when(@test.is('test'))
|
304
|
+
run_command('delete')
|
305
|
+
end
|
306
|
+
end
|
307
|
+
end
|
308
|
+
|
309
|
+
describe "when the command is 'log'" do
|
310
|
+
before :each do
|
311
|
+
Punch.stubs(:log).when(@test.is('setup'))
|
312
|
+
@message = 'log message'
|
313
|
+
end
|
314
|
+
|
315
|
+
it 'should load punch data' do
|
316
|
+
Punch.expects(:load)
|
317
|
+
run_command('log', @project, @message)
|
318
|
+
end
|
319
|
+
|
320
|
+
it 'should log a message for the given project' do
|
321
|
+
@test.become('test')
|
322
|
+
Punch.stubs(:write)
|
323
|
+
Punch.expects(:log).with(@project, @message).when(@test.is('test'))
|
324
|
+
run_command('log', @project, @message)
|
325
|
+
end
|
326
|
+
|
327
|
+
it 'should output the result' do
|
328
|
+
result = 'result'
|
329
|
+
Punch.stubs(:log).returns(result)
|
330
|
+
self.expects(:puts).with(result.inspect)
|
331
|
+
run_command('log', @project, @message)
|
332
|
+
end
|
333
|
+
|
334
|
+
describe 'when logged successfully' do
|
335
|
+
it 'should write the data' do
|
336
|
+
@test.become('test')
|
337
|
+
Punch.stubs(:log).returns(true)
|
338
|
+
Punch.expects(:write).when(@test.is('test'))
|
339
|
+
run_command('log', @project, @message)
|
340
|
+
end
|
341
|
+
end
|
342
|
+
|
343
|
+
describe 'when not deleted successfully' do
|
344
|
+
it 'should not write the data' do
|
345
|
+
@test.become('test')
|
346
|
+
Punch.stubs(:log).returns(false)
|
347
|
+
Punch.expects(:write).never.when(@test.is('test'))
|
348
|
+
run_command('log', @project, @message)
|
349
|
+
end
|
350
|
+
end
|
351
|
+
|
352
|
+
describe 'when no project given' do
|
353
|
+
it 'should display an error message' do
|
354
|
+
self.expects(:puts).with(regexp_matches(/project.+require/i))
|
355
|
+
run_command('log')
|
356
|
+
end
|
357
|
+
|
358
|
+
it 'should not log' do
|
359
|
+
@test.become('test')
|
360
|
+
Punch.stubs(:write)
|
361
|
+
Punch.expects(:log).never.when(@test.is('test'))
|
362
|
+
run_command('log')
|
363
|
+
end
|
364
|
+
|
365
|
+
it 'should not write the data' do
|
366
|
+
@test.become('test')
|
367
|
+
Punch.expects(:write).never.when(@test.is('test'))
|
368
|
+
run_command('log')
|
369
|
+
end
|
370
|
+
end
|
371
|
+
|
372
|
+
describe 'when no message given' do
|
373
|
+
it 'should display an error message' do
|
374
|
+
self.expects(:puts).with(regexp_matches(/message.+require/i))
|
375
|
+
run_command('log', @project)
|
376
|
+
end
|
377
|
+
|
378
|
+
it 'should not log' do
|
379
|
+
@test.become('test')
|
380
|
+
Punch.stubs(:write)
|
381
|
+
Punch.expects(:log).never.when(@test.is('test'))
|
382
|
+
run_command('log', @project)
|
383
|
+
end
|
384
|
+
|
385
|
+
it 'should not write the data' do
|
386
|
+
@test.become('test')
|
387
|
+
Punch.expects(:write).never.when(@test.is('test'))
|
388
|
+
run_command('log', @project)
|
389
|
+
end
|
390
|
+
end
|
391
|
+
end
|
392
|
+
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.0
|
4
|
+
version: 0.1.0
|
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-
|
12
|
+
date: 2008-08-26 00:00:00 -05:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|
@@ -25,8 +25,8 @@ dependencies:
|
|
25
25
|
description: a simple time-tracking tool
|
26
26
|
email:
|
27
27
|
- ymendel@pobox.com
|
28
|
-
executables:
|
29
|
-
|
28
|
+
executables:
|
29
|
+
- punch
|
30
30
|
extensions: []
|
31
31
|
|
32
32
|
extra_rdoc_files:
|
@@ -40,6 +40,7 @@ files:
|
|
40
40
|
- Manifest.txt
|
41
41
|
- README.txt
|
42
42
|
- Rakefile
|
43
|
+
- bin/punch
|
43
44
|
- config/hoe.rb
|
44
45
|
- config/requirements.rb
|
45
46
|
- lib/punch.rb
|
@@ -48,6 +49,7 @@ files:
|
|
48
49
|
- script/destroy
|
49
50
|
- script/generate
|
50
51
|
- setup.rb
|
52
|
+
- spec/punch_command_spec.rb
|
51
53
|
- spec/punch_spec.rb
|
52
54
|
- spec/spec.opts
|
53
55
|
- spec/spec_helper.rb
|