one_inch_punch 0.2.3 → 0.2.4
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +7 -1
- data/bin/punch +6 -4
- data/lib/punch/instance.rb +2 -2
- data/lib/punch/version.rb +1 -1
- data/lib/punch.rb +11 -3
- data/spec/punch_command_spec.rb +26 -2
- data/spec/punch_instance_spec.rb +26 -1
- data/spec/punch_spec.rb +32 -0
- metadata +2 -2
data/History.txt
CHANGED
@@ -1,6 +1,12 @@
|
|
1
|
+
== 0.2.4 2008-12-17
|
2
|
+
|
3
|
+
* 1 tiny enhancement:
|
4
|
+
* Status can now be retrieved as simple (only the status) or 'full' (status + time)
|
5
|
+
* punch command displays status as YAML unless only retrieving simple status for a single project
|
6
|
+
|
1
7
|
== 0.2.3 2008-12-11
|
2
8
|
|
3
|
-
* 1
|
9
|
+
* 1 enhancement:
|
4
10
|
* Logging a message now automatically adds a time
|
5
11
|
* A time can be specified for the log message (with now as a default)
|
6
12
|
* punch command takes options for message logging
|
data/bin/punch
CHANGED
@@ -33,6 +33,8 @@ BANNER
|
|
33
33
|
"Use the given time to punch in/out") { |time| OPTIONS[:time] = Time.parse(time) }
|
34
34
|
opts.on('-m', '--message [MESSAGE]', String,
|
35
35
|
"Add the given log message when punching in/out") { |message| OPTIONS[:message] = message }
|
36
|
+
opts.on('--full',
|
37
|
+
"Show full output for the command") { |full| OPTIONS[:full] = true }
|
36
38
|
opts.on("-h", "--help",
|
37
39
|
"Show this help message.") { puts opts; exit }
|
38
40
|
opts.parse!(ARGV)
|
@@ -55,11 +57,11 @@ Punch.load
|
|
55
57
|
|
56
58
|
commands = {
|
57
59
|
'status' => lambda do |project|
|
58
|
-
result = Punch.status(project)
|
59
|
-
if project
|
60
|
-
puts result.inspect
|
61
|
-
else
|
60
|
+
result = Punch.status(project, OPTIONS)
|
61
|
+
if project.nil? or OPTIONS[:full]
|
62
62
|
puts result.to_yaml
|
63
|
+
else
|
64
|
+
puts result.inspect
|
63
65
|
end
|
64
66
|
end,
|
65
67
|
'total' => lambda do |project|
|
data/lib/punch/instance.rb
CHANGED
data/lib/punch/version.rb
CHANGED
data/lib/punch.rb
CHANGED
@@ -39,14 +39,22 @@ class Punch
|
|
39
39
|
end
|
40
40
|
end
|
41
41
|
|
42
|
-
def status(project = nil)
|
43
|
-
|
42
|
+
def status(project = nil, options = {})
|
43
|
+
if project.is_a?(Hash)
|
44
|
+
options = project
|
45
|
+
project = nil
|
46
|
+
end
|
47
|
+
|
48
|
+
return data.keys.inject({}) { |hash, project| hash.merge(project => status(project, options)) } unless project
|
44
49
|
|
45
50
|
project_data = data[project]
|
46
51
|
return nil if !project_data or project_data.empty?
|
47
52
|
|
48
53
|
time_data = project_data.last
|
49
|
-
time_data['out'] ? 'out' : 'in'
|
54
|
+
status = time_data['out'] ? 'out' : 'in'
|
55
|
+
return status unless options[:full]
|
56
|
+
|
57
|
+
{ :status => status, :time => time_data[status] }
|
50
58
|
end
|
51
59
|
|
52
60
|
def out?(project)
|
data/spec/punch_command_spec.rb
CHANGED
@@ -147,12 +147,12 @@ describe 'punch command' do
|
|
147
147
|
end
|
148
148
|
|
149
149
|
it 'should get the status for the requested project' do
|
150
|
-
Punch.should.receive(:status).with(@project)
|
150
|
+
Punch.should.receive(:status).with(@project, {})
|
151
151
|
run_command('status', @project)
|
152
152
|
end
|
153
153
|
|
154
154
|
it 'should get the status for all projects if none given' do
|
155
|
-
Punch.should.receive(:status).with(nil)
|
155
|
+
Punch.should.receive(:status).with(nil, {})
|
156
156
|
run_command('status')
|
157
157
|
end
|
158
158
|
|
@@ -170,6 +170,30 @@ describe 'punch command' do
|
|
170
170
|
run_command('status')
|
171
171
|
end
|
172
172
|
|
173
|
+
it 'should pass a true full option if specified on the command line (with --full)' do
|
174
|
+
Punch.should.receive(:status).with(@project, :full => true)
|
175
|
+
run_command('status', @project, '--full')
|
176
|
+
end
|
177
|
+
|
178
|
+
it 'should pass a true full option if specified on the command line (with --full) and no project given' do
|
179
|
+
Punch.should.receive(:status).with(nil, :full => true)
|
180
|
+
run_command('status', '--full')
|
181
|
+
end
|
182
|
+
|
183
|
+
it 'should output the status as YAML if a full option is given' do
|
184
|
+
result = 'status data'
|
185
|
+
Punch.stub!(:status).and_return(result)
|
186
|
+
self.should.receive(:puts).with(result.to_yaml)
|
187
|
+
run_command('status', @project, '--full')
|
188
|
+
end
|
189
|
+
|
190
|
+
it 'should output the status as YAML if not project given even if a full option is given' do
|
191
|
+
result = 'status data'
|
192
|
+
Punch.stub!(:status).and_return(result)
|
193
|
+
self.should.receive(:puts).with(result.to_yaml)
|
194
|
+
run_command('status', '--full')
|
195
|
+
end
|
196
|
+
|
173
197
|
it 'should not write the data' do
|
174
198
|
Punch.should.receive(:write).never
|
175
199
|
run_command('status')
|
data/spec/punch_instance_spec.rb
CHANGED
@@ -30,13 +30,38 @@ describe Punch, 'instance' do
|
|
30
30
|
Punch.stub!(:status).and_return(@status)
|
31
31
|
end
|
32
32
|
|
33
|
+
it 'should accept options' do
|
34
|
+
lambda { @punch.status(:full => true) }.should.not.raise(ArgumentError)
|
35
|
+
end
|
36
|
+
|
37
|
+
it 'should not require options' do
|
38
|
+
lambda { @punch.status }.should.not.raise(ArgumentError)
|
39
|
+
end
|
40
|
+
|
33
41
|
it 'should delegate to the class' do
|
34
42
|
Punch.should.receive(:status)
|
35
43
|
@punch.status
|
36
44
|
end
|
37
45
|
|
38
46
|
it 'should pass the project when delegating to the class' do
|
39
|
-
Punch.should.receive(:status)
|
47
|
+
Punch.should.receive(:status) do |proj, _|
|
48
|
+
proj.should == @project
|
49
|
+
end
|
50
|
+
@punch.status
|
51
|
+
end
|
52
|
+
|
53
|
+
it 'should pass the options when delegating to the class' do
|
54
|
+
options = { :full => true }
|
55
|
+
Punch.should.receive(:status) do |_, opts|
|
56
|
+
opts.should == options
|
57
|
+
end
|
58
|
+
@punch.status(options)
|
59
|
+
end
|
60
|
+
|
61
|
+
it 'should pass an empty hash if no options given' do
|
62
|
+
Punch.should.receive(:status) do |_, opts|
|
63
|
+
opts.should == {}
|
64
|
+
end
|
40
65
|
@punch.status
|
41
66
|
end
|
42
67
|
|
data/spec/punch_spec.rb
CHANGED
@@ -210,6 +210,38 @@ describe Punch do
|
|
210
210
|
it 'should return the status of all projects if no project name given' do
|
211
211
|
Punch.status.should == { @projects['out'] => 'out', @projects['in'] => 'in' }
|
212
212
|
end
|
213
|
+
|
214
|
+
it 'should accept options' do
|
215
|
+
lambda { Punch.status('proj', :full => true) }.should.not.raise(ArgumentError)
|
216
|
+
end
|
217
|
+
|
218
|
+
describe 'when given a :full option' do
|
219
|
+
it 'should return the status and the time of that status if the project is currently punched in' do
|
220
|
+
Punch.status(@projects['in'], :full => true).should == { :status => 'in', :time => @now }
|
221
|
+
end
|
222
|
+
|
223
|
+
it 'should return the status and the time of that status if the project is currently punched out' do
|
224
|
+
Punch.status(@projects['out'], :full => true).should == { :status => 'out', :time => @now + 12 }
|
225
|
+
end
|
226
|
+
|
227
|
+
it 'should return nil if project does not exist' do
|
228
|
+
Punch.status('other project', :full => true).should.be.nil
|
229
|
+
end
|
230
|
+
|
231
|
+
it 'should return the full status if all projects if nil is given as the project' do
|
232
|
+
Punch.status(nil, :full => true).should == {
|
233
|
+
@projects['out'] => { :status => 'out', :time => @now + 12 },
|
234
|
+
@projects['in'] => { :status => 'in', :time => @now }
|
235
|
+
}
|
236
|
+
end
|
237
|
+
|
238
|
+
it 'should return the full status if all projects if no project given' do
|
239
|
+
Punch.status(:full => true).should == {
|
240
|
+
@projects['out'] => { :status => 'out', :time => @now + 12 },
|
241
|
+
@projects['in'] => { :status => 'in', :time => @now }
|
242
|
+
}
|
243
|
+
end
|
244
|
+
end
|
213
245
|
end
|
214
246
|
|
215
247
|
it 'should indicate whether a project is punched out' do
|
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.2.
|
4
|
+
version: 0.2.4
|
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-12-
|
12
|
+
date: 2008-12-17 00:00:00 -06:00
|
13
13
|
default_executable:
|
14
14
|
dependencies:
|
15
15
|
- !ruby/object:Gem::Dependency
|