one_inch_punch 0.1.4 → 0.2.0

Sign up to get free protection for your applications and to get access to all the features.
data/History.txt CHANGED
@@ -1,3 +1,9 @@
1
+ == 0.2.0 2008-11-05
2
+
3
+ * 2 enhancements:
4
+ * Ensures data is loaded when needed
5
+ * Can be instantiated with a project (useful if many operations are to be performed on a single project)
6
+
1
7
  == 0.1.4 2008-10-23
2
8
 
3
9
  * punch command enhancements:
data/Manifest.txt CHANGED
@@ -10,12 +10,14 @@ lib/punch.rb
10
10
  lib/punch/core_ext.rb
11
11
  lib/punch/core_ext/fixnum.rb
12
12
  lib/punch/version.rb
13
+ lib/punch/instance.rb
13
14
  script/console
14
15
  script/destroy
15
16
  script/generate
16
17
  setup.rb
17
18
  spec/fixnum_spec.rb
18
19
  spec/punch_command_spec.rb
20
+ spec/punch_instance_spec.rb
19
21
  spec/punch_spec.rb
20
22
  spec/spec.opts
21
23
  spec/spec_helper.rb
data/README.txt CHANGED
@@ -40,6 +40,19 @@ One-inch punch: Smaller, more effective
40
40
  $ echo 'working, really'
41
41
  $ punch out proj
42
42
  $ punch status
43
+
44
+ or!
45
+
46
+ require 'punch'
47
+
48
+ proj = Punch.new('my project')
49
+ proj.status # => 'out'
50
+ proj.in
51
+ proj.status # => 'in'
52
+ # do some work
53
+ proj.out
54
+ proj.out? # => true
55
+ Punch.write
43
56
 
44
57
  == REQUIREMENTS:
45
58
 
data/lib/punch.rb CHANGED
@@ -3,11 +3,18 @@ $:.unshift(File.dirname(__FILE__)) unless
3
3
 
4
4
  require 'yaml'
5
5
  require 'punch/core_ext'
6
+ require 'punch/instance'
6
7
 
7
- module Punch
8
+ class Punch
8
9
  class << self
9
10
  private
10
- attr_accessor :data
11
+ attr_writer :data
12
+
13
+ def data
14
+ load unless @data
15
+ @data
16
+ end
17
+
11
18
 
12
19
  public
13
20
 
@@ -28,7 +35,7 @@ module Punch
28
35
 
29
36
  def write
30
37
  File.open(File.expand_path('~/.punch.yml'), 'w') do |file|
31
- file.puts @data.to_yaml
38
+ file.puts data.to_yaml
32
39
  end
33
40
  end
34
41
 
@@ -0,0 +1,39 @@
1
+ class Punch
2
+ attr_reader :project
3
+
4
+ def initialize(project)
5
+ @project = project
6
+ end
7
+
8
+ def status
9
+ self.class.status(project)
10
+ end
11
+
12
+ def out?
13
+ self.class.out?(project)
14
+ end
15
+
16
+ def in?
17
+ self.class.in?(project)
18
+ end
19
+
20
+ def in(options = {})
21
+ self.class.in(project, options)
22
+ end
23
+
24
+ def out(options = {})
25
+ self.class.out(project, options)
26
+ end
27
+
28
+ def list(options = {})
29
+ self.class.list(project, options)
30
+ end
31
+
32
+ def total(options = {})
33
+ self.class.total(project, options)
34
+ end
35
+
36
+ def log(message)
37
+ self.class.log(project, message)
38
+ end
39
+ end
data/lib/punch/version.rb CHANGED
@@ -1,8 +1,8 @@
1
- module Punch
1
+ class Punch
2
2
  module VERSION #:nodoc:
3
3
  MAJOR = 0
4
- MINOR = 1
5
- TINY = 4
4
+ MINOR = 2
5
+ TINY = 0
6
6
 
7
7
  STRING = [MAJOR, MINOR, TINY].join('.')
8
8
  end
@@ -0,0 +1,312 @@
1
+ require File.dirname(__FILE__) + '/spec_helper.rb'
2
+
3
+ describe Punch, 'instance' do
4
+ before :each do
5
+ @project = 'proj'
6
+ @punch = Punch.new(@project)
7
+ end
8
+
9
+ describe 'when initialized' do
10
+ it 'should accept a project' do
11
+ lambda { Punch.new(@project) }.should_not raise_error(ArgumentError)
12
+ end
13
+
14
+ it 'should require a project' do
15
+ lambda { Punch.new }.should raise_error(ArgumentError)
16
+ end
17
+
18
+ it 'should save the project for later use' do
19
+ Punch.new(@project).project.should == @project
20
+ end
21
+ end
22
+
23
+ it 'should give project status' do
24
+ @punch.should respond_to(:status)
25
+ end
26
+
27
+ describe 'giving project status' do
28
+ before :each do
29
+ @status = 'status val'
30
+ Punch.stubs(:status).returns(@status)
31
+ end
32
+
33
+ it 'should delegate to the class' do
34
+ Punch.expects(:status)
35
+ @punch.status
36
+ end
37
+
38
+ it 'should pass the project when delegating to the class' do
39
+ Punch.expects(:status).with(@project)
40
+ @punch.status
41
+ end
42
+
43
+ it 'should return the value returned by the class method' do
44
+ @punch.status.should == @status
45
+ end
46
+ end
47
+
48
+ it 'should indicate whether the project is punched out' do
49
+ @punch.should respond_to(:out?)
50
+ end
51
+
52
+ describe 'indicating whether the project is punched out' do
53
+ before :each do
54
+ @out = 'out val'
55
+ Punch.stubs(:out?).returns(@out)
56
+ end
57
+
58
+ it 'should delegate to the class' do
59
+ Punch.expects(:out?)
60
+ @punch.out?
61
+ end
62
+
63
+ it 'should pass the project when delegating to the class' do
64
+ Punch.expects(:out?).with(@project)
65
+ @punch.out?
66
+ end
67
+
68
+ it 'should return the value returned by the class method' do
69
+ @punch.out?.should == @out
70
+ end
71
+ end
72
+
73
+ it 'should indicate whether the project is punched in' do
74
+ @punch.should respond_to(:in?)
75
+ end
76
+
77
+ describe 'indicating whether the project is punched in' do
78
+ before :each do
79
+ @in = 'in val'
80
+ Punch.stubs(:in?).returns(@in)
81
+ end
82
+
83
+ it 'should delegate to the class' do
84
+ Punch.expects(:in?)
85
+ @punch.in?
86
+ end
87
+
88
+ it 'should pass the project when delegating to the class' do
89
+ Punch.expects(:in?).with(@project)
90
+ @punch.in?
91
+ end
92
+
93
+ it 'should return the value returned by the class method' do
94
+ @punch.in?.should == @in
95
+ end
96
+ end
97
+
98
+ it 'should punch the project in' do
99
+ @punch.should respond_to(:in)
100
+ end
101
+
102
+ describe 'punching the project in' do
103
+ before :each do
104
+ @in = 'in val'
105
+ Punch.stubs(:in).returns(@in)
106
+ end
107
+
108
+ it 'should accept options' do
109
+ lambda { @punch.in(:time => Time.now) }.should_not raise_error(ArgumentError)
110
+ end
111
+
112
+ it 'should not require options' do
113
+ lambda { @punch.in }.should_not raise_error(ArgumentError)
114
+ end
115
+
116
+ it 'should delegate to the class' do
117
+ Punch.expects(:in)
118
+ @punch.in
119
+ end
120
+
121
+ it 'should pass the project when delegating to the class' do
122
+ Punch.expects(:in).with(@project, anything)
123
+ @punch.in
124
+ end
125
+
126
+ it 'should pass the options when delegating to the class' do
127
+ options = { :time => Time.now }
128
+ Punch.expects(:in).with(anything, options)
129
+ @punch.in(options)
130
+ end
131
+
132
+ it 'should pass an empty hash if no options given' do
133
+ Punch.expects(:in).with(anything, {})
134
+ @punch.in
135
+ end
136
+
137
+ it 'should return the value returned by the class method' do
138
+ @punch.in.should == @in
139
+ end
140
+ end
141
+
142
+ it 'should punch the project out' do
143
+ @punch.should respond_to(:out)
144
+ end
145
+
146
+ describe 'punching the project out' do
147
+ before :each do
148
+ @out = 'out val'
149
+ Punch.stubs(:out).returns(@out)
150
+ end
151
+
152
+ it 'should accept options' do
153
+ lambda { @punch.out(:time => Time.now) }.should_not raise_error(ArgumentError)
154
+ end
155
+
156
+ it 'should not require options' do
157
+ lambda { @punch.out }.should_not raise_error(ArgumentError)
158
+ end
159
+
160
+ it 'should delegate to the class' do
161
+ Punch.expects(:out)
162
+ @punch.out
163
+ end
164
+
165
+ it 'should pass the project when delegating to the class' do
166
+ Punch.expects(:out).with(@project, anything)
167
+ @punch.out
168
+ end
169
+
170
+ it 'should pass the options when delegating to the class' do
171
+ options = { :time => Time.now }
172
+ Punch.expects(:out).with(anything, options)
173
+ @punch.out(options)
174
+ end
175
+
176
+ it 'should pass an empty hash if no options given' do
177
+ Punch.expects(:out).with(anything, {})
178
+ @punch.out
179
+ end
180
+
181
+ it 'should return the value returned by the class method' do
182
+ @punch.out.should == @out
183
+ end
184
+ end
185
+
186
+ it 'should list the project data' do
187
+ @punch.should respond_to(:list)
188
+ end
189
+
190
+ describe 'listing the project data' do
191
+ before :each do
192
+ @list = 'list val'
193
+ Punch.stubs(:list).returns(@list)
194
+ end
195
+
196
+ it 'should accept options' do
197
+ lambda { @punch.list(:time => Time.now) }.should_not raise_error(ArgumentError)
198
+ end
199
+
200
+ it 'should not require options' do
201
+ lambda { @punch.list }.should_not raise_error(ArgumentError)
202
+ end
203
+
204
+ it 'should delegate to the class' do
205
+ Punch.expects(:list)
206
+ @punch.list
207
+ end
208
+
209
+ it 'should pass the project when delegating to the class' do
210
+ Punch.expects(:list).with(@project, anything)
211
+ @punch.list
212
+ end
213
+
214
+ it 'should pass the options when delegating to the class' do
215
+ options = { :time => Time.now }
216
+ Punch.expects(:list).with(anything, options)
217
+ @punch.list(options)
218
+ end
219
+
220
+ it 'should pass an empty hash if no options given' do
221
+ Punch.expects(:list).with(anything, {})
222
+ @punch.list
223
+ end
224
+
225
+ it 'should return the value returned by the class method' do
226
+ @punch.list.should == @list
227
+ end
228
+ end
229
+
230
+ it 'should get the project total' do
231
+ @punch.should respond_to(:total)
232
+ end
233
+
234
+ describe 'getting the project total' do
235
+ before :each do
236
+ @total = 'total val'
237
+ Punch.stubs(:total).returns(@total)
238
+ end
239
+
240
+ it 'should accept options' do
241
+ lambda { @punch.total(:time => Time.now) }.should_not raise_error(ArgumentError)
242
+ end
243
+
244
+ it 'should not require options' do
245
+ lambda { @punch.total }.should_not raise_error(ArgumentError)
246
+ end
247
+
248
+ it 'should delegate to the class' do
249
+ Punch.expects(:total)
250
+ @punch.total
251
+ end
252
+
253
+ it 'should pass the project when delegating to the class' do
254
+ Punch.expects(:total).with(@project, anything)
255
+ @punch.total
256
+ end
257
+
258
+ it 'should pass the options when delegating to the class' do
259
+ options = { :time => Time.now }
260
+ Punch.expects(:total).with(anything, options)
261
+ @punch.total(options)
262
+ end
263
+
264
+ it 'should pass an empty hash if no options given' do
265
+ Punch.expects(:total).with(anything, {})
266
+ @punch.total
267
+ end
268
+
269
+ it 'should return the value returned by the class method' do
270
+ @punch.total.should == @total
271
+ end
272
+ end
273
+
274
+ it 'should log information about the project' do
275
+ @punch.should respond_to(:log)
276
+ end
277
+
278
+ describe 'logging information about the project' do
279
+ before :each do
280
+ @log = 'log val'
281
+ @message = 'some log message'
282
+ Punch.stubs(:log).returns(@log)
283
+ end
284
+
285
+ it 'should accept a log message' do
286
+ lambda { @punch.log(@message) }.should_not raise_error(ArgumentError)
287
+ end
288
+
289
+ it 'should require a log message' do
290
+ lambda { @punch.log }.should raise_error(ArgumentError)
291
+ end
292
+
293
+ it 'should delegate to the class' do
294
+ Punch.expects(:log)
295
+ @punch.log(@message)
296
+ end
297
+
298
+ it 'should pass the project when delegating to the class' do
299
+ Punch.expects(:log).with(@project, anything)
300
+ @punch.log(@message)
301
+ end
302
+
303
+ it 'should pass the message when delegating to the class' do
304
+ Punch.expects(:log).with(anything, @message)
305
+ @punch.log(@message)
306
+ end
307
+
308
+ it 'should return the value returned by the class method' do
309
+ @punch.log(@message).should == @log
310
+ end
311
+ end
312
+ end
data/spec/punch_spec.rb CHANGED
@@ -34,7 +34,7 @@ describe Punch do
34
34
 
35
35
  Punch.instance_eval do
36
36
  class << self
37
- public :data
37
+ public :data, :data=
38
38
  end
39
39
  end
40
40
 
@@ -71,6 +71,19 @@ describe Punch do
71
71
  Punch.load.should == false
72
72
  end
73
73
  end
74
+
75
+ describe 'and returning data' do
76
+ it 'should return the data if set' do
77
+ val = { 'rip' => [] }
78
+ Punch.data = val
79
+ Punch.data.should == val
80
+ end
81
+
82
+ it 'should load the data if not set' do
83
+ Punch.data = nil
84
+ Punch.data.should == YAML.load(@data)
85
+ end
86
+ end
74
87
  end
75
88
 
76
89
  it 'should reset itself' do
@@ -89,7 +102,7 @@ describe Punch do
89
102
  it 'should set its data to nil' do
90
103
  Punch.data = { 'proj' => 'lots of stuff here' }
91
104
  Punch.reset
92
- Punch.data.should be_nil
105
+ Punch.instance_variable_get('@data').should be_nil
93
106
  end
94
107
  end
95
108
 
@@ -363,7 +376,7 @@ describe Punch do
363
376
 
364
377
  it 'should create the project' do
365
378
  Punch.in(@project)
366
- Punch.data.should include(@project)
379
+ Punch.data.should have_key(@project)
367
380
  end
368
381
 
369
382
  it 'should add a time entry to the project data' do
@@ -607,7 +620,7 @@ describe Punch do
607
620
  describe 'when the project exists' do
608
621
  it 'should remove the project data' do
609
622
  Punch.delete(@project)
610
- Punch.data.should_not include(@project)
623
+ Punch.data.should_not have_key(@project)
611
624
  end
612
625
 
613
626
  it 'should return true' 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.1.4
4
+ version: 0.2.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-10-23 00:00:00 -05:00
12
+ date: 2008-11-05 00:00:00 -06:00
13
13
  default_executable:
14
14
  dependencies:
15
15
  - !ruby/object:Gem::Dependency
@@ -67,12 +67,14 @@ files:
67
67
  - lib/punch/core_ext.rb
68
68
  - lib/punch/core_ext/fixnum.rb
69
69
  - lib/punch/version.rb
70
+ - lib/punch/instance.rb
70
71
  - script/console
71
72
  - script/destroy
72
73
  - script/generate
73
74
  - setup.rb
74
75
  - spec/fixnum_spec.rb
75
76
  - spec/punch_command_spec.rb
77
+ - spec/punch_instance_spec.rb
76
78
  - spec/punch_spec.rb
77
79
  - spec/spec.opts
78
80
  - spec/spec_helper.rb
@@ -103,7 +105,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
103
105
  requirements: []
104
106
 
105
107
  rubyforge_project: yomendel
106
- rubygems_version: 1.3.0
108
+ rubygems_version: 1.3.1
107
109
  signing_key:
108
110
  specification_version: 2
109
111
  summary: a simple time-tracking tool