cron-spec 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- data/.idea/cron-spec.iml +5 -0
- data/.idea/workspace.xml +30 -53
- data/README.rdoc +55 -2
- data/VERSION +1 -1
- data/cron-spec.gemspec +2 -2
- data/lib/cron-spec/cron_specification.rb +40 -1
- data/lib/cron-spec/cron_specification_factory.rb +16 -1
- data/lib/cron-spec/cron_value_base.rb +14 -1
- data/lib/cron-spec/day_factory.rb +9 -1
- data/lib/cron-spec/dow_factory.rb +16 -1
- data/lib/cron-spec/hour_factory.rb +9 -1
- data/lib/cron-spec/minute_factory.rb +8 -1
- data/lib/cron-spec/month_factory.rb +15 -1
- data/lib/cron-spec/range_cron_value.rb +17 -1
- data/lib/cron-spec/single_value_cron_value.rb +13 -1
- data/lib/cron-spec/step_cron_value.rb +13 -1
- data/lib/cron-spec/wildcard_cron_value.rb +10 -1
- metadata +4 -4
data/.idea/cron-spec.iml
CHANGED
@@ -35,6 +35,11 @@
|
|
35
35
|
<orderEntry type="library" scope="PROVIDED" name="[gem] rcov (v0.9.8, /Users/dave/.rvm/gems/ruby-1.9.2-p0@rails3/gems/rcov-0.9.8)" level="application" />
|
36
36
|
<orderEntry type="library" scope="PROVIDED" name="[gem] git (v1.2.5, /Users/dave/.rvm/gems/ruby-1.9.2-p0@rails3/gems/git-1.2.5)" level="application" />
|
37
37
|
<orderEntry type="library" scope="PROVIDED" name="[gem] rake (v0.8.7, /Users/dave/.rvm/gems/ruby-1.9.2-p0@rails3/gems/rake-0.8.7)" level="application" />
|
38
|
+
<orderEntry type="library" scope="PROVIDED" name="[gem] rspec (v2.1.0, /Users/dave/.rvm/gems/ruby-1.9.2-p0@rails3/gems/rspec-2.1.0)" level="application" />
|
39
|
+
<orderEntry type="library" scope="PROVIDED" name="[gem] rspec-core (v2.1.0, /Users/dave/.rvm/gems/ruby-1.9.2-p0@rails3/gems/rspec-core-2.1.0)" level="application" />
|
40
|
+
<orderEntry type="library" scope="PROVIDED" name="[gem] diff-lcs (v1.1.2, /Users/dave/.rvm/gems/ruby-1.9.2-p0@rails3/gems/diff-lcs-1.1.2)" level="application" />
|
41
|
+
<orderEntry type="library" scope="PROVIDED" name="[gem] rspec-mocks (v2.1.0, /Users/dave/.rvm/gems/ruby-1.9.2-p0@rails3/gems/rspec-mocks-2.1.0)" level="application" />
|
42
|
+
<orderEntry type="library" scope="PROVIDED" name="[gem] rspec-expectations (v2.1.0, /Users/dave/.rvm/gems/ruby-1.9.2-p0@rails3/gems/rspec-expectations-2.1.0)" level="application" />
|
38
43
|
</component>
|
39
44
|
</module>
|
40
45
|
|
data/.idea/workspace.xml
CHANGED
@@ -1,7 +1,9 @@
|
|
1
1
|
<?xml version="1.0" encoding="UTF-8"?>
|
2
2
|
<project version="4">
|
3
3
|
<component name="ChangeListManager">
|
4
|
-
<list default="true" id="5a15dc32-6ade-4091-9f48-a1ce07241214" name="Default" comment=""
|
4
|
+
<list default="true" id="5a15dc32-6ade-4091-9f48-a1ce07241214" name="Default" comment="">
|
5
|
+
<change type="MODIFICATION" beforePath="$PROJECT_DIR$/.idea/workspace.xml" afterPath="$PROJECT_DIR$/.idea/workspace.xml" />
|
6
|
+
</list>
|
5
7
|
<ignored path="cron-spec.iws" />
|
6
8
|
<ignored path=".idea/workspace.xml" />
|
7
9
|
<option name="TRACKING_ENABLED" value="true" />
|
@@ -27,7 +29,7 @@
|
|
27
29
|
<file leaf-file-name="Rakefile" pinned="false" current="false" current-in-tab="false">
|
28
30
|
<entry file="file://$PROJECT_DIR$/Rakefile">
|
29
31
|
<provider selected="true" editor-type-id="text-editor">
|
30
|
-
<state line="26" column="55" selection-start="1012" selection-end="1012" vertical-scroll-proportion="
|
32
|
+
<state line="26" column="55" selection-start="1012" selection-end="1012" vertical-scroll-proportion="0.0">
|
31
33
|
<folding />
|
32
34
|
</state>
|
33
35
|
</provider>
|
@@ -36,7 +38,7 @@
|
|
36
38
|
<file leaf-file-name="single_value_cron_value_spec.rb" pinned="false" current="false" current-in-tab="false">
|
37
39
|
<entry file="file://$PROJECT_DIR$/spec/single_value_cron_value_spec.rb">
|
38
40
|
<provider selected="true" editor-type-id="text-editor">
|
39
|
-
<state line="1" column="0" selection-start="22" selection-end="22" vertical-scroll-proportion="
|
41
|
+
<state line="1" column="0" selection-start="22" selection-end="22" vertical-scroll-proportion="0.0">
|
40
42
|
<folding />
|
41
43
|
</state>
|
42
44
|
</provider>
|
@@ -45,7 +47,7 @@
|
|
45
47
|
<file leaf-file-name="cron_specification_spec.rb" pinned="false" current="true" current-in-tab="true">
|
46
48
|
<entry file="file://$PROJECT_DIR$/spec/cron_specification_spec.rb">
|
47
49
|
<provider selected="true" editor-type-id="text-editor">
|
48
|
-
<state line="
|
50
|
+
<state line="10" column="12" selection-start="336" selection-end="336" vertical-scroll-proportion="0.27173913">
|
49
51
|
<folding />
|
50
52
|
</state>
|
51
53
|
</provider>
|
@@ -169,6 +171,7 @@
|
|
169
171
|
</component>
|
170
172
|
<component name="TaskManager">
|
171
173
|
<task active="true" id="Default" summary="Default task">
|
174
|
+
<changelist id="5a15dc32-6ade-4091-9f48-a1ce07241214" name="Default" comment="" />
|
172
175
|
<created>1298829562652</created>
|
173
176
|
<updated>1298829562652</updated>
|
174
177
|
</task>
|
@@ -178,22 +181,22 @@
|
|
178
181
|
<frame x="142" y="22" width="1538" height="959" extended-state="0" />
|
179
182
|
<editor active="false" />
|
180
183
|
<layout>
|
181
|
-
<window_info id="
|
182
|
-
<window_info id="Changes" active="true" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.3298731" sideWeight="0.5" order="-1" side_tool="false" content_ui="tabs" />
|
184
|
+
<window_info id="Changes" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.3298731" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
|
183
185
|
<window_info id="TODO" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="6" side_tool="false" content_ui="tabs" />
|
184
186
|
<window_info id="Structure" active="false" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="1" side_tool="true" content_ui="tabs" />
|
185
|
-
<window_info id="Dependency Viewer" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="
|
186
|
-
<window_info id="Project" active="
|
187
|
+
<window_info id="Dependency Viewer" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
|
188
|
+
<window_info id="Project" active="true" anchor="left" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="true" weight="0.24966975" sideWeight="0.67012686" order="0" side_tool="false" content_ui="tabs" />
|
187
189
|
<window_info id="Debug" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="3" side_tool="false" content_ui="tabs" />
|
188
190
|
<window_info id="Run" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="2" side_tool="false" content_ui="tabs" />
|
189
|
-
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="
|
191
|
+
<window_info id="Version Control" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
|
190
192
|
<window_info id="Cvs" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="4" side_tool="false" content_ui="tabs" />
|
191
193
|
<window_info id="Message" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
|
192
|
-
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
|
193
194
|
<window_info id="Ant Build" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
|
195
|
+
<window_info id="Find" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="1" side_tool="false" content_ui="tabs" />
|
196
|
+
<window_info id="Messages" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.33" sideWeight="0.5" order="7" side_tool="false" content_ui="tabs" />
|
194
197
|
<window_info id="Commander" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="0" side_tool="false" content_ui="tabs" />
|
195
|
-
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
|
196
198
|
<window_info id="Hierarchy" active="false" anchor="right" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.25" sideWeight="0.5" order="2" side_tool="false" content_ui="combo" />
|
199
|
+
<window_info id="Inspection" active="false" anchor="bottom" auto_hide="false" internal_type="DOCKED" type="DOCKED" visible="false" weight="0.4" sideWeight="0.5" order="5" side_tool="false" content_ui="tabs" />
|
197
200
|
</layout>
|
198
201
|
</component>
|
199
202
|
<component name="VcsManagerConfiguration">
|
@@ -232,112 +235,86 @@
|
|
232
235
|
<component name="editorHistoryManager">
|
233
236
|
<entry file="file://$PROJECT_DIR$/lib/cron-spec/minute_factory.rb">
|
234
237
|
<provider selected="true" editor-type-id="text-editor">
|
235
|
-
<state line="2" column="28" selection-start="45" selection-end="45" vertical-scroll-proportion="0.037926674"
|
236
|
-
<folding />
|
237
|
-
</state>
|
238
|
+
<state line="2" column="28" selection-start="45" selection-end="45" vertical-scroll-proportion="0.037926674" />
|
238
239
|
</provider>
|
239
240
|
</entry>
|
240
241
|
<entry file="file://$PROJECT_DIR$/lib/cron-spec/hour_factory.rb">
|
241
242
|
<provider selected="true" editor-type-id="text-editor">
|
242
|
-
<state line="2" column="26" selection-start="43" selection-end="43" vertical-scroll-proportion="0.037926674"
|
243
|
-
<folding />
|
244
|
-
</state>
|
243
|
+
<state line="2" column="26" selection-start="43" selection-end="43" vertical-scroll-proportion="0.037926674" />
|
245
244
|
</provider>
|
246
245
|
</entry>
|
247
246
|
<entry file="file://$PROJECT_DIR$/lib/cron-spec/dow_factory.rb">
|
248
247
|
<provider selected="true" editor-type-id="text-editor">
|
249
|
-
<state line="1" column="25" selection-start="41" selection-end="41" vertical-scroll-proportion="0.018963337"
|
250
|
-
<folding />
|
251
|
-
</state>
|
248
|
+
<state line="1" column="25" selection-start="41" selection-end="41" vertical-scroll-proportion="0.018963337" />
|
252
249
|
</provider>
|
253
250
|
</entry>
|
254
251
|
<entry file="file://$PROJECT_DIR$/lib/cron-spec/day_factory.rb">
|
255
252
|
<provider selected="true" editor-type-id="text-editor">
|
256
|
-
<state line="1" column="25" selection-start="41" selection-end="41" vertical-scroll-proportion="0.018963337"
|
257
|
-
<folding />
|
258
|
-
</state>
|
253
|
+
<state line="1" column="25" selection-start="41" selection-end="41" vertical-scroll-proportion="0.018963337" />
|
259
254
|
</provider>
|
260
255
|
</entry>
|
261
256
|
<entry file="file://$PROJECT_DIR$/spec/wildcard_cron_value_spec.rb">
|
262
257
|
<provider selected="true" editor-type-id="text-editor">
|
263
|
-
<state line="1" column="0" selection-start="22" selection-end="22" vertical-scroll-proportion="0.018495684"
|
264
|
-
<folding />
|
265
|
-
</state>
|
258
|
+
<state line="1" column="0" selection-start="22" selection-end="22" vertical-scroll-proportion="0.018495684" />
|
266
259
|
</provider>
|
267
260
|
</entry>
|
268
261
|
<entry file="file://$PROJECT_DIR$/spec/step_cron_value_spec.rb">
|
269
262
|
<provider selected="true" editor-type-id="text-editor">
|
270
|
-
<state line="1" column="0" selection-start="22" selection-end="22" vertical-scroll-proportion="0.018495684"
|
271
|
-
<folding />
|
272
|
-
</state>
|
263
|
+
<state line="1" column="0" selection-start="22" selection-end="22" vertical-scroll-proportion="0.018495684" />
|
273
264
|
</provider>
|
274
265
|
</entry>
|
275
266
|
<entry file="file://$PROJECT_DIR$/spec/range_cron_value_spec.rb">
|
276
267
|
<provider selected="true" editor-type-id="text-editor">
|
277
|
-
<state line="0" column="6" selection-start="6" selection-end="6" vertical-scroll-proportion="-0.0"
|
278
|
-
<folding />
|
279
|
-
</state>
|
268
|
+
<state line="0" column="6" selection-start="6" selection-end="6" vertical-scroll-proportion="-0.0" />
|
280
269
|
</provider>
|
281
270
|
</entry>
|
282
271
|
<entry file="file://$PROJECT_DIR$/VERSION">
|
283
272
|
<provider selected="true" editor-type-id="text-editor">
|
284
|
-
<state line="0" column="19" selection-start="5" selection-end="5" vertical-scroll-proportion="0.0"
|
285
|
-
<folding />
|
286
|
-
</state>
|
273
|
+
<state line="0" column="19" selection-start="5" selection-end="5" vertical-scroll-proportion="0.0" />
|
287
274
|
</provider>
|
288
275
|
</entry>
|
289
276
|
<entry file="file://$PROJECT_DIR$/.document">
|
290
277
|
<provider selected="true" editor-type-id="text-editor">
|
291
|
-
<state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0"
|
292
|
-
<folding />
|
293
|
-
</state>
|
278
|
+
<state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0" />
|
294
279
|
</provider>
|
295
280
|
</entry>
|
296
281
|
<entry file="file://$PROJECT_DIR$/README.rdoc">
|
297
282
|
<provider selected="true" editor-type-id="text-editor">
|
298
|
-
<state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0"
|
299
|
-
<folding />
|
300
|
-
</state>
|
283
|
+
<state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0" />
|
301
284
|
</provider>
|
302
285
|
</entry>
|
303
286
|
<entry file="file://$PROJECT_DIR$/.rspec">
|
304
287
|
<provider selected="true" editor-type-id="text-editor">
|
305
|
-
<state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0"
|
306
|
-
<folding />
|
307
|
-
</state>
|
288
|
+
<state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0" />
|
308
289
|
</provider>
|
309
290
|
</entry>
|
310
291
|
<entry file="file://$PROJECT_DIR$/Gemfile">
|
311
292
|
<provider selected="true" editor-type-id="text-editor">
|
312
|
-
<state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0"
|
313
|
-
<folding />
|
314
|
-
</state>
|
293
|
+
<state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0" />
|
315
294
|
</provider>
|
316
295
|
</entry>
|
317
296
|
<entry file="file://$PROJECT_DIR$/LICENSE.txt">
|
318
297
|
<provider selected="true" editor-type-id="text-editor">
|
319
|
-
<state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0"
|
320
|
-
<folding />
|
321
|
-
</state>
|
298
|
+
<state line="0" column="0" selection-start="0" selection-end="0" vertical-scroll-proportion="0.0" />
|
322
299
|
</provider>
|
323
300
|
</entry>
|
324
301
|
<entry file="file://$PROJECT_DIR$/Rakefile">
|
325
302
|
<provider selected="true" editor-type-id="text-editor">
|
326
|
-
<state line="26" column="55" selection-start="1012" selection-end="1012" vertical-scroll-proportion="
|
303
|
+
<state line="26" column="55" selection-start="1012" selection-end="1012" vertical-scroll-proportion="0.0">
|
327
304
|
<folding />
|
328
305
|
</state>
|
329
306
|
</provider>
|
330
307
|
</entry>
|
331
308
|
<entry file="file://$PROJECT_DIR$/spec/single_value_cron_value_spec.rb">
|
332
309
|
<provider selected="true" editor-type-id="text-editor">
|
333
|
-
<state line="1" column="0" selection-start="22" selection-end="22" vertical-scroll-proportion="
|
310
|
+
<state line="1" column="0" selection-start="22" selection-end="22" vertical-scroll-proportion="0.0">
|
334
311
|
<folding />
|
335
312
|
</state>
|
336
313
|
</provider>
|
337
314
|
</entry>
|
338
315
|
<entry file="file://$PROJECT_DIR$/spec/cron_specification_spec.rb">
|
339
316
|
<provider selected="true" editor-type-id="text-editor">
|
340
|
-
<state line="
|
317
|
+
<state line="10" column="12" selection-start="336" selection-end="336" vertical-scroll-proportion="0.27173913">
|
341
318
|
<folding />
|
342
319
|
</state>
|
343
320
|
</provider>
|
data/README.rdoc
CHANGED
@@ -1,6 +1,59 @@
|
|
1
|
-
= cron-spec
|
1
|
+
= cron-spec - Exposing the cron syntax as a time filter
|
2
2
|
|
3
|
-
|
3
|
+
cron-spec provides the Ruby developer with a way to leverage the cron
|
4
|
+
syntax to add flexible time filtering for his/her code.
|
5
|
+
|
6
|
+
Most cron-aware people see the cron syntax as a way to fire off an activity
|
7
|
+
at a specific time/day/month, etc. There are a variety of tools out there
|
8
|
+
that handle this sort of activity. cron-spec tries to address a different
|
9
|
+
subset of problems. In particular, cron-spec allows the developer to ask if
|
10
|
+
a particular date/time is effective with respect to a cron specification.
|
11
|
+
|
12
|
+
For example, a web application might want to display a message to the end-user
|
13
|
+
each Friday between the hours of 8AM and 5PM indicating that there will be
|
14
|
+
a maintenance that night. The developer could simply define a cron
|
15
|
+
specification like '* 8-17 * * fri', then for each end-user request, check
|
16
|
+
the current time against this specification to determine whether or not
|
17
|
+
to display the message. This specification is much more succinct than other - more explicit - types of filter specifications.
|
18
|
+
|
19
|
+
== Installing
|
20
|
+
|
21
|
+
Since cron-spec is a gem, installing is relatively straightforward:
|
22
|
+
|
23
|
+
gem install cron-spec
|
24
|
+
|
25
|
+
== Usage
|
26
|
+
|
27
|
+
To use a cron specification as a time filter simply construct a new
|
28
|
+
specification, then ask if it is in effect.
|
29
|
+
|
30
|
+
cs = CronSpec::CronSpecification.new("* 8-17 * * fri")
|
31
|
+
cs.is_specification_in_effect?(Time.now) # => true/false
|
32
|
+
|
33
|
+
cron-spec handles most - if not all - the standard cron syntax illustrated
|
34
|
+
below:
|
35
|
+
|
36
|
+
There are several special predefined values which can be used to substitute the CRON expression.
|
37
|
+
Entry Description Equivalent To
|
38
|
+
@yearly (or @annually) Run once a year 0 0 1 1 *
|
39
|
+
@monthly Run once a month 0 0 1 * *
|
40
|
+
@weekly Run once a week 0 0 * * 0
|
41
|
+
@daily (or @midnight) Run once a day 0 0 * * *
|
42
|
+
@hourly Run once an hour 0 * * * *
|
43
|
+
|
44
|
+
* * * * *
|
45
|
+
- - - - -
|
46
|
+
| | | | |
|
47
|
+
| | | | +----- day of week (0 - 6) (Sunday=0)
|
48
|
+
| | | +---------- month (1 - 12)
|
49
|
+
| | +--------------- day of month (1 - 31)
|
50
|
+
| +-------------------- hour (0 - 23)
|
51
|
+
+------------------------- min (0 - 59)
|
52
|
+
|
53
|
+
The following named entries can be used:
|
54
|
+
|
55
|
+
* Day of week - sun, mon, tue, wed, thu, fri, sat
|
56
|
+
* Month - jan feb mar apr may jun jul aug sep oct nov dec
|
4
57
|
|
5
58
|
== Contributing to cron-spec
|
6
59
|
|
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/cron-spec.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{cron-spec}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Dave Sieh"]
|
12
|
-
s.date = %q{2011-02-
|
12
|
+
s.date = %q{2011-02-28}
|
13
13
|
s.description = %q{Cron specification implementation}
|
14
14
|
s.email = %q{dave.sieh@nursinghomequality.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -1,4 +1,10 @@
|
|
1
1
|
module CronSpec
|
2
|
+
|
3
|
+
##
|
4
|
+
# Encapsulates the interpretation of a cron specification and
|
5
|
+
# provides a method which determines if the specified time is effective
|
6
|
+
# with respect to the specification.
|
7
|
+
#
|
2
8
|
class CronSpecification
|
3
9
|
|
4
10
|
TimeMethods = [ :min, :hour, :day, :month, :wday ]
|
@@ -31,6 +37,35 @@ module CronSpec
|
|
31
37
|
|
32
38
|
attr_reader :raw_specification
|
33
39
|
|
40
|
+
##
|
41
|
+
# Constructs a new CronSpecification with a textual cron specificiation.
|
42
|
+
#
|
43
|
+
# A broad cron syntax is supported:
|
44
|
+
#
|
45
|
+
# * * * * *
|
46
|
+
# - - - - -
|
47
|
+
# | | | | |
|
48
|
+
# | | | | +----- day of week (0 - 6) (Sunday=0)
|
49
|
+
# | | | +---------- month (1 - 12)
|
50
|
+
# | | +--------------- day of month (1 - 31)
|
51
|
+
# | +-------------------- hour (0 - 23)
|
52
|
+
# +------------------------- min (0 - 59)
|
53
|
+
#
|
54
|
+
# The following named entries can be used:
|
55
|
+
#
|
56
|
+
# * Day of week - sun, mon, tue, wed, thu, fri, sat
|
57
|
+
# * Month - jan feb mar apr may jun jul aug sep oct nov dec
|
58
|
+
#
|
59
|
+
# The following constructs are supported:
|
60
|
+
#
|
61
|
+
# * Ranges are supported (e.g. 2-10 or mon-fri)
|
62
|
+
# * Multiple values are supported (e.g. 2,3,8 or mon,wed,fri)
|
63
|
+
# * Wildcards are supported (e.g. *)
|
64
|
+
# * Step values are supported (e.g. */4)
|
65
|
+
# * Combinations of all but wildcard are supported (e.g. 2,*/3,8-10)
|
66
|
+
#
|
67
|
+
# A single space is required between each group.
|
68
|
+
#
|
34
69
|
def initialize(raw_specification)
|
35
70
|
raise "Must specify a cron specification" if raw_specification.nil?
|
36
71
|
|
@@ -47,7 +82,11 @@ module CronSpec
|
|
47
82
|
@cron_values << parse_specification(specification[DOW], DowFactory.new)
|
48
83
|
end
|
49
84
|
|
50
|
-
|
85
|
+
##
|
86
|
+
# Return true if the specified time falls within the definition of the
|
87
|
+
# CronSpecification. The parameter defaults to the current time.
|
88
|
+
#
|
89
|
+
def is_specification_in_effect?(time=Time.now)
|
51
90
|
idx = 0
|
52
91
|
test_results = @cron_values.collect do | cvalues |
|
53
92
|
time_value = time.send(TimeMethods[idx])
|
@@ -1,5 +1,8 @@
|
|
1
1
|
module CronSpec
|
2
2
|
|
3
|
+
##
|
4
|
+
# Base class for the definition of CronSpecificationFactory classes.
|
5
|
+
#
|
3
6
|
class CronSpecificationFactory
|
4
7
|
|
5
8
|
WildcardPattern = /\A\*\z/
|
@@ -7,12 +10,24 @@ module CronSpec
|
|
7
10
|
RangePattern = /\A(\d+)-(\d+)\z/
|
8
11
|
StepPattern = /\A\*\/(\d+)\z/
|
9
12
|
|
13
|
+
##
|
14
|
+
# Constructs a new CronSpecificationFactory
|
15
|
+
#
|
10
16
|
def initialize
|
11
17
|
@single_value_pattern = SingleValuePattern
|
12
18
|
@range_pattern = RangePattern
|
13
19
|
@step_pattern = StepPattern
|
14
20
|
end
|
15
21
|
|
22
|
+
##
|
23
|
+
# Parses a unit of a cron specification.
|
24
|
+
# The supported patterns for parsing are one of:
|
25
|
+
#
|
26
|
+
# * Wildcard '*'
|
27
|
+
# * Single Scalar Value [0-9]+|(sun|mon|tue|wed|thu|fri|sat)|(jan|feb|mar|apr|may|jun|jul|aug|sep|oct|nov|dec)
|
28
|
+
# * Range value (0-9, mon-fri, etc.)
|
29
|
+
# * Step value (*/[0-9]+)
|
30
|
+
#
|
16
31
|
def parse(value_spec)
|
17
32
|
case value_spec
|
18
33
|
when WildcardPattern
|
@@ -36,4 +51,4 @@ module CronSpec
|
|
36
51
|
|
37
52
|
end
|
38
53
|
|
39
|
-
end
|
54
|
+
end
|
@@ -1,9 +1,18 @@
|
|
1
1
|
module CronSpec
|
2
2
|
|
3
|
+
##
|
4
|
+
# Base class for parsed cron values.
|
5
|
+
#
|
3
6
|
class CronValueBase
|
4
7
|
|
5
8
|
attr_reader :lower_limit, :upper_limit
|
6
9
|
|
10
|
+
##
|
11
|
+
# Constructs a new CronValueBase with the upper and lower limits of
|
12
|
+
# values allowed for this CronValue. For example, when definiting a
|
13
|
+
# CronValue for a 'minute', the lower limit would be 0 and the upper
|
14
|
+
# limit would be 59.
|
15
|
+
#
|
7
16
|
def initialize(lower_limit, upper_limit)
|
8
17
|
@lower_limit = lower_limit
|
9
18
|
@upper_limit = upper_limit
|
@@ -11,9 +20,13 @@ module CronSpec
|
|
11
20
|
raise "Lower limit must be less than or equal to upper limit" if @lower_limit > @upper_limit
|
12
21
|
end
|
13
22
|
|
23
|
+
##
|
24
|
+
# Returns true if the specified value is with the upper and lower
|
25
|
+
# limits defined for this CronValue.
|
26
|
+
#
|
14
27
|
def is_value_within_limits?(value)
|
15
28
|
value >= @lower_limit && value <= upper_limit
|
16
29
|
end
|
17
30
|
end
|
18
31
|
|
19
|
-
end
|
32
|
+
end
|
@@ -1,12 +1,20 @@
|
|
1
1
|
module CronSpec
|
2
|
+
##
|
3
|
+
# Factory for constructing Day CronValues from a cron specification.
|
4
|
+
#
|
2
5
|
class DayFactory < CronSpecificationFactory
|
6
|
+
|
7
|
+
# The lower limit for a value representing a day of the month
|
3
8
|
DayLowerLimit = 1
|
9
|
+
# The upper limit for a value representing a day of the month
|
4
10
|
DayUpperLimit = 31
|
5
11
|
|
12
|
+
##
|
13
|
+
# Constructs a new DayFactory object.
|
6
14
|
def initialize
|
7
15
|
super
|
8
16
|
@lower_limit = DayLowerLimit
|
9
17
|
@upper_limit = DayUpperLimit
|
10
18
|
end
|
11
19
|
end
|
12
|
-
end
|
20
|
+
end
|
@@ -1,19 +1,33 @@
|
|
1
1
|
module CronSpec
|
2
|
+
|
3
|
+
##
|
4
|
+
# Factory for constructing Day of week values from a cron specification.
|
5
|
+
#
|
2
6
|
class DowFactory < CronSpecificationFactory
|
3
7
|
|
8
|
+
# The lower limit for the value of a day of the week (0-Sunday)
|
4
9
|
DayOfWeekLowerLimit = 0
|
10
|
+
# The upper limit for the value of a day of the week (6-Saturday)
|
5
11
|
DayOfWeekUpperLimit = 6
|
6
12
|
|
13
|
+
# The supported names for the days of the week
|
7
14
|
DaysOfWeek = %w{ sun mon tue wed thu fri sat }
|
8
15
|
|
16
|
+
# A pipe-delimited expression for the days of the week
|
9
17
|
DayOfWeekExpression = DaysOfWeek.join('|')
|
10
18
|
|
19
|
+
# A regular expression that matches a single day of the week.
|
11
20
|
DayOfWeekSingleValuePattern = /\A(#{DayOfWeekExpression}|\d)\z/
|
12
21
|
|
22
|
+
# Regular expression that matches a range of days of the week
|
13
23
|
DayOfWeekRangePattern = /\A(#{DayOfWeekExpression}|\d)-(#{DayOfWeekExpression}|\d)\z/
|
14
24
|
|
25
|
+
# Regular expression that matches only a named day of the week.
|
15
26
|
NamedDayOfWeekPattern = /\A(#{DayOfWeekExpression})\z/
|
16
27
|
|
28
|
+
##
|
29
|
+
# Constructs a new DowFactory object.
|
30
|
+
#
|
17
31
|
def initialize
|
18
32
|
super
|
19
33
|
@lower_limit = DayOfWeekLowerLimit
|
@@ -29,5 +43,6 @@ module CronSpec
|
|
29
43
|
# Sunday can be specified as index 7
|
30
44
|
(dow == 7) ? 0 : dow
|
31
45
|
end
|
46
|
+
|
32
47
|
end
|
33
|
-
end
|
48
|
+
end
|
@@ -1,10 +1,18 @@
|
|
1
1
|
module CronSpec
|
2
2
|
|
3
|
+
##
|
4
|
+
# Factory for constructing hour cron values from a cron specification.
|
5
|
+
#
|
3
6
|
class HourFactory < CronSpecificationFactory
|
4
7
|
|
8
|
+
# The lower limit of a value representing an hour of the day.
|
5
9
|
HourLowerLimit = 0
|
10
|
+
# The upper limit of a value representing an hour of the day.
|
6
11
|
HourUpperLimit = 23
|
7
12
|
|
13
|
+
##
|
14
|
+
# Constructs a new HourFactory object.
|
15
|
+
#
|
8
16
|
def initialize
|
9
17
|
super
|
10
18
|
@lower_limit = HourLowerLimit
|
@@ -13,4 +21,4 @@ module CronSpec
|
|
13
21
|
|
14
22
|
end
|
15
23
|
|
16
|
-
end
|
24
|
+
end
|
@@ -1,10 +1,17 @@
|
|
1
1
|
module CronSpec
|
2
2
|
|
3
|
+
##
|
4
|
+
# Factory for constructing minute cron values from a cron specification.
|
5
|
+
#
|
3
6
|
class MinuteFactory < CronSpecificationFactory
|
4
7
|
|
8
|
+
# The lower limit of a value representing a minute of an hour
|
5
9
|
MinuteLowerLimit = 0
|
10
|
+
# The upper limit of a value representing a minute of an hour
|
6
11
|
MinuteUpperLimit = 59
|
7
12
|
|
13
|
+
##
|
14
|
+
# Constructs a new MinuteFactory object.
|
8
15
|
def initialize
|
9
16
|
super
|
10
17
|
@lower_limit = MinuteLowerLimit
|
@@ -13,4 +20,4 @@ module CronSpec
|
|
13
20
|
|
14
21
|
end
|
15
22
|
|
16
|
-
end
|
23
|
+
end
|
@@ -1,19 +1,33 @@
|
|
1
1
|
module CronSpec
|
2
|
+
|
3
|
+
##
|
4
|
+
# Factory for constructing month cron values from a cron specification.
|
5
|
+
#
|
2
6
|
class MonthFactory < CronSpecificationFactory
|
3
7
|
|
8
|
+
# The lower limit for a value representing a month of a year
|
4
9
|
MonthLowerLimit = 1
|
10
|
+
# The upper limit for a value representing a month of a year
|
5
11
|
MonthUpperLimit = 12
|
6
12
|
|
13
|
+
# The supported names of the months
|
7
14
|
Months = %w{ jan feb mar apr may jun jul aug sep oct nov dec }
|
8
15
|
|
16
|
+
# A pipe-delimited list of the months of the year
|
9
17
|
MonthExpression = Months.join('|')
|
10
18
|
|
19
|
+
# A regular expression to match a single value month expression
|
11
20
|
MonthSingleValuePattern = /\A(#{MonthExpression}|\d+)\z/
|
12
21
|
|
22
|
+
# A regular expression to match a range month expression
|
13
23
|
MonthRangePattern = /\A(#{MonthExpression}|\d+)-(#{MonthExpression}|\d+)\z/
|
14
24
|
|
25
|
+
# A regular expression to match a named month
|
15
26
|
NamedMonthPattern = /\A(#{MonthExpression})\z/
|
16
27
|
|
28
|
+
##
|
29
|
+
# Constructs a new MonthFactory object.
|
30
|
+
#
|
17
31
|
def initialize
|
18
32
|
super
|
19
33
|
@lower_limit = MonthLowerLimit
|
@@ -29,4 +43,4 @@ module CronSpec
|
|
29
43
|
end
|
30
44
|
|
31
45
|
end
|
32
|
-
end
|
46
|
+
end
|
@@ -1,9 +1,21 @@
|
|
1
1
|
module CronSpec
|
2
2
|
|
3
|
+
##
|
4
|
+
# A cron value representing a range of values
|
5
|
+
#
|
3
6
|
class RangeCronValue < CronValueBase
|
4
7
|
|
5
8
|
attr_reader :range_lower, :range_upper
|
6
9
|
|
10
|
+
##
|
11
|
+
# Constructs a new RangeCronValue object. The object is initialized
|
12
|
+
# with the value limits (lower_limit and upper_limit) and the
|
13
|
+
# defined sub-range of the lower/upper limits.
|
14
|
+
#
|
15
|
+
# The range_lower and range_upper values are checked to determine if
|
16
|
+
# they are within the value limits and are not reversed. If they are not
|
17
|
+
# within limits or reversed an exception is raised.
|
18
|
+
#
|
7
19
|
def initialize(lower_limit, upper_limit, range_lower, range_upper)
|
8
20
|
super(lower_limit, upper_limit)
|
9
21
|
@range_lower = range_lower
|
@@ -14,10 +26,14 @@ module CronSpec
|
|
14
26
|
raise "Lower limit must be less than or equal to the upper limit" if @range_lower > @range_upper
|
15
27
|
end
|
16
28
|
|
29
|
+
##
|
30
|
+
# Returns true if the specified value is with the range_upper/range_lower
|
31
|
+
# value range, inclusive.
|
32
|
+
#
|
17
33
|
def is_effective?(value)
|
18
34
|
@range_lower <= value && value <= @range_upper
|
19
35
|
end
|
20
36
|
|
21
37
|
end
|
22
38
|
|
23
|
-
end
|
39
|
+
end
|
@@ -1,9 +1,17 @@
|
|
1
1
|
module CronSpec
|
2
2
|
|
3
|
+
##
|
4
|
+
# A single cron value
|
5
|
+
#
|
3
6
|
class SingleValueCronValue < CronValueBase
|
4
7
|
|
5
8
|
attr_reader :single_value
|
6
9
|
|
10
|
+
##
|
11
|
+
# Constructs a new SingleValueCronValue having the specified limits
|
12
|
+
# and value. The value is checked to determine if it fits within the
|
13
|
+
# specified limits; if it doesn't, an exception is raised.
|
14
|
+
#
|
7
15
|
def initialize(lower_limit, upper_limit, single_value)
|
8
16
|
super(lower_limit, upper_limit)
|
9
17
|
|
@@ -12,10 +20,14 @@ module CronSpec
|
|
12
20
|
raise "Value is out of range: #{@single_value}" unless is_value_within_limits?(@single_value)
|
13
21
|
end
|
14
22
|
|
23
|
+
##
|
24
|
+
# Returns true if the specified value is equal to the value encapsulated
|
25
|
+
# by the SingleValueCronValue.
|
26
|
+
#
|
15
27
|
def is_effective?(value)
|
16
28
|
@single_value == value
|
17
29
|
end
|
18
30
|
|
19
31
|
end
|
20
32
|
|
21
|
-
end
|
33
|
+
end
|
@@ -1,9 +1,17 @@
|
|
1
1
|
module CronSpec
|
2
2
|
|
3
|
+
##
|
4
|
+
# Defines an instance of a step value within a cron specification.
|
5
|
+
#
|
3
6
|
class StepCronValue < CronValueBase
|
4
7
|
|
5
8
|
attr_reader :step_value
|
6
9
|
|
10
|
+
##
|
11
|
+
# Constructs a new StepCronValue with the specified lower and upper limits
|
12
|
+
# and step value. If the step value is 0 or is not less than or equal to
|
13
|
+
# the upper limit, an exception is raised.
|
14
|
+
#
|
7
15
|
def initialize(lower_limit, upper_limit, step_value)
|
8
16
|
super(lower_limit, upper_limit)
|
9
17
|
|
@@ -12,10 +20,14 @@ module CronSpec
|
|
12
20
|
raise "Invalid step value: #{@step_value}" if step_value == 0 || step_value > upper_limit
|
13
21
|
end
|
14
22
|
|
23
|
+
##
|
24
|
+
# Returns true if the specified value represents a value step value within
|
25
|
+
# the step specification. Verifies that value % step_value == 0
|
26
|
+
#
|
15
27
|
def is_effective?(value)
|
16
28
|
value % @step_value == 0
|
17
29
|
end
|
18
30
|
|
19
31
|
end
|
20
32
|
|
21
|
-
end
|
33
|
+
end
|
@@ -1,15 +1,24 @@
|
|
1
1
|
module CronSpec
|
2
2
|
|
3
|
+
##
|
4
|
+
# Represents a wildcard value
|
5
|
+
#
|
3
6
|
class WildcardCronValue < CronValueBase
|
4
7
|
|
8
|
+
##
|
9
|
+
# Constructs a new WildcardCronValue with the specified limits.
|
10
|
+
#
|
5
11
|
def initialize(lower_limit, upper_limit)
|
6
12
|
super(lower_limit, upper_limit)
|
7
13
|
end
|
8
14
|
|
15
|
+
##
|
16
|
+
# Returns true if the specified value is any value whatsoever.
|
17
|
+
#
|
9
18
|
def is_effective?(value)
|
10
19
|
true
|
11
20
|
end
|
12
21
|
|
13
22
|
end
|
14
23
|
|
15
|
-
end
|
24
|
+
end
|
metadata
CHANGED
@@ -5,8 +5,8 @@ version: !ruby/object:Gem::Version
|
|
5
5
|
segments:
|
6
6
|
- 0
|
7
7
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
8
|
+
- 1
|
9
|
+
version: 0.1.1
|
10
10
|
platform: ruby
|
11
11
|
authors:
|
12
12
|
- Dave Sieh
|
@@ -14,7 +14,7 @@ autorequire:
|
|
14
14
|
bindir: bin
|
15
15
|
cert_chain: []
|
16
16
|
|
17
|
-
date: 2011-02-
|
17
|
+
date: 2011-02-28 00:00:00 -07:00
|
18
18
|
default_executable:
|
19
19
|
dependencies:
|
20
20
|
- !ruby/object:Gem::Dependency
|
@@ -136,7 +136,7 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
136
136
|
requirements:
|
137
137
|
- - ">="
|
138
138
|
- !ruby/object:Gem::Version
|
139
|
-
hash:
|
139
|
+
hash: -3901467252571771135
|
140
140
|
segments:
|
141
141
|
- 0
|
142
142
|
version: "0"
|