when-cron 1.0.2 → 1.0.3

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 420cf2151fc72d5f0b8826761b8b5f0a826539d0
4
- data.tar.gz: 43452faf5af725c4c9b6e73a123beea17ac51285
3
+ metadata.gz: e2398cff23356ee6c9aec3e565f53189d20fe6f1
4
+ data.tar.gz: 55539ece23018256655584532f24753a342a97fe
5
5
  SHA512:
6
- metadata.gz: b9b1fb00c0b8239626e911b6d438eb97573571825977f05d910a15d7b1ac0e56d6fe6f8baf77fc1ea2fab95af4a390c1a821893b4b47a254d08f68f4df8710e7
7
- data.tar.gz: 8c230d9008b79afc09e9d1a48d36fc853a644a3b9bb031498ccd2f533fdbcfe744180b879027d8fddbb7bea132ca98bff082dbfb098b358341c9cf44c2c7b303
6
+ metadata.gz: 9cc06fa82520f6ecdb0ee50bf1935d5172455278c00a1df4cb29fa82b96e4c5a26145506639f599c86e68987d8c36dd2c381370cb5ad559f7e2334a3ff6f5d5b
7
+ data.tar.gz: b86f68fa09dcfd2205b5d10d1f6d484e5e0d8c1ac646dec6cb69bc640a7eacba2fe1aadaf62f71346ed4ba68616fc15efd9edecd8f0599a83397003f3ac58fa2
data/README.md CHANGED
@@ -37,6 +37,11 @@ When::Cron will raise an error for extremely nonsensical cron strings.
37
37
 
38
38
  ```When::Cron.new('this is getting ridiculous') # => raises When::Cron::InvalidString```
39
39
 
40
+ When::Cron follows this rule (man 5 crontab)
41
+
42
+ > Note: The day of a command's execution can be specified by two fields -- day of month, and day of week. If both fields are restricted (ie, are not *), the command will be run
43
+ when either field matches the current time. For example, ``30 4 1,15 * 5'' would cause a command to be run at 4:30 am on the 1st and 15th of each month, plus every Friday.
44
+
40
45
  ## Contributing
41
46
 
42
47
  1. Fork it
@@ -17,9 +17,16 @@ module When
17
17
 
18
18
  @minute == time.min &&
19
19
  @hour == time.hour &&
20
- @day == time.day &&
21
20
  @month == time.month &&
22
- @wday == time.wday
21
+ day_of_week_and_or_day_of_month?(time)
22
+ end
23
+
24
+ def day_of_week_and_or_day_of_month?(time)
25
+ if @day.wildcard? || @wday.wildcard?
26
+ @day == time.day && @wday == time.wday
27
+ else
28
+ @day == time.day || @wday == time.wday
29
+ end
23
30
  end
24
31
 
25
32
  private
@@ -35,6 +35,10 @@ module When
35
35
  @part == int
36
36
  end
37
37
 
38
+ def wildcard?
39
+ @part.kind_of? Wildcard
40
+ end
41
+
38
42
  private
39
43
 
40
44
  def parse(cron_part)
@@ -158,4 +158,22 @@ describe CronPart do
158
158
  end
159
159
  end
160
160
  end
161
+
162
+ describe '#wildcard?' do
163
+ context 'part is a wildcard' do
164
+ let(:cron_part) { CronPart.new('*') }
165
+
166
+ it 'returns true' do
167
+ expect(cron_part.wildcard?).to eq true
168
+ end
169
+ end
170
+
171
+ context 'part is not a wildcard' do
172
+ let(:cron_part) { CronPart.new('1') }
173
+
174
+ it 'returns false' do
175
+ expect(cron_part.wildcard?).to eq false
176
+ end
177
+ end
178
+ end
161
179
  end
@@ -3,6 +3,10 @@ include When
3
3
 
4
4
  describe Cron do
5
5
  let(:now) { Time.new(2013, 6, 15, 12, 30, 30) }
6
+ let(:hour_earlier) { now - 3600 }
7
+ let(:day_earlier) { now - 3600 * 24 }
8
+ let(:week_earlier) { now - 3600 * 24 * 7 }
9
+ let(:month_earlier) { now - 3600 * 24 * 31 }
6
10
 
7
11
  describe '.valid?' do
8
12
  it 'returns false for strings it cannot interpret' do
@@ -31,23 +35,92 @@ describe Cron do
31
35
  describe '#==' do
32
36
  context 'simple cron' do
33
37
  let(:cron) { Cron.new('30 12 15 6 6') }
38
+
34
39
  it 'returns true for now' do
35
40
  expect(cron == now).to eq true
36
41
  end
37
42
 
38
43
  it 'returns false for an hour earlier' do
39
- expect(cron == now - 3600).to eq false
44
+ expect(cron == hour_earlier).to eq false
45
+ end
46
+
47
+ it 'returns true a week earlier' do
48
+ expect(cron == week_earlier).to eq true
49
+ end
50
+
51
+ end
52
+
53
+ context 'day of week and day of month' do
54
+ context 'day of week is wildcard' do
55
+ let(:cron) { Cron.new('30 12 15 * *') }
56
+
57
+ it 'returns true for now' do
58
+ expect(cron == now).to eq true
59
+ end
60
+
61
+ it 'returns false for an hour earlier' do
62
+ expect(cron == hour_earlier).to eq false
63
+ end
64
+
65
+ it 'returns false a week earlier' do
66
+ expect(cron == week_earlier).to eq false
67
+ end
68
+
69
+ it 'returns true a month earlier' do
70
+ expect(cron == month_earlier).to eq true
71
+ end
72
+ end
73
+
74
+ context 'day of month is wildcard' do
75
+ let(:cron) { Cron.new('30 12 * * 6') }
76
+
77
+ it 'returns true for now' do
78
+ expect(cron == now).to eq true
79
+ end
80
+
81
+ it 'returns false for an hour earlier' do
82
+ expect(cron == hour_earlier).to eq false
83
+ end
84
+
85
+ it 'returns true a week earlier' do
86
+ expect(cron == week_earlier).to eq true
87
+ end
88
+
89
+ it 'returns false a month earlier' do
90
+ expect(cron == month_earlier).to eq false
91
+ end
92
+ end
93
+
94
+ context 'neither is wildcard' do
95
+ let(:cron) { Cron.new('30 12 15 * 6') }
96
+
97
+ it 'returns true for now' do
98
+ expect(cron == now).to eq true
99
+ end
100
+
101
+ it 'returns false for an hour earlier' do
102
+ expect(cron == hour_earlier).to eq false
103
+ end
104
+
105
+ it 'returns true a week earlier' do
106
+ expect(cron == week_earlier).to eq true
107
+ end
108
+
109
+ it 'returns true a month earlier' do
110
+ expect(cron == month_earlier).to eq true
111
+ end
40
112
  end
41
113
  end
42
114
 
43
115
  context 'complex cron' do
44
116
  let(:cron) { Cron.new('25-35/5 */12 */5 4-8/2 6') }
117
+
45
118
  it 'returns true for now' do
46
119
  expect(cron == now).to eq true
47
120
  end
48
121
 
49
122
  it 'returns false for an hour earlier' do
50
- expect(cron == now - 3600).to eq false
123
+ expect(cron == hour_earlier).to eq false
51
124
  end
52
125
  end
53
126
 
@@ -59,7 +132,7 @@ describe Cron do
59
132
  end
60
133
 
61
134
  it 'returns false for a day earlier' do
62
- expect(cron == now - 3600 * 24).to eq false
135
+ expect(cron == day_earlier).to eq false
63
136
  end
64
137
  end
65
138
  end
data/when-cron.gemspec CHANGED
@@ -4,7 +4,7 @@ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
4
 
5
5
  Gem::Specification.new do |spec|
6
6
  spec.name = "when-cron"
7
- spec.version = '1.0.2'
7
+ spec.version = '1.0.3'
8
8
  spec.authors = ["TH"]
9
9
  spec.email = ["tylerhartland7@gmail.com"]
10
10
  spec.description = %q{A basic cron implementation.}
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: when-cron
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.2
4
+ version: 1.0.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - TH
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2014-08-29 00:00:00.000000000 Z
11
+ date: 2014-11-12 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
@@ -134,7 +134,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
134
134
  version: '0'
135
135
  requirements: []
136
136
  rubyforge_project:
137
- rubygems_version: 2.1.11
137
+ rubygems_version: 2.2.2
138
138
  signing_key:
139
139
  specification_version: 4
140
140
  summary: A basic cron implementation.
@@ -148,3 +148,4 @@ test_files:
148
148
  - spec/lib/when/cron/wildcard_spec.rb
149
149
  - spec/lib/when_spec.rb
150
150
  - spec/spec_helper.rb
151
+ has_rdoc: