whedon 0.0.1 → 0.0.2
Sign up to get free protection for your applications and to get access to all the features.
- data/.travis.yml +5 -0
- data/README.md +3 -1
- data/lib/whedon/schedule.rb +9 -7
- data/lib/whedon/version.rb +2 -4
- data/spec/whedon/schedule_spec.rb +11 -11
- data/whedon.gemspec +1 -1
- metadata +2 -1
data/.travis.yml
ADDED
data/README.md
CHANGED
@@ -3,7 +3,9 @@
|
|
3
3
|
The goal of this gem is to parse a crontab timing specification and produce an
|
4
4
|
object that can be queried about the schedule.
|
5
5
|
|
6
|
-
This gem began as an extraction of Rufus::CronLine from the rufus-
|
6
|
+
This gem began as an extraction of Rufus::CronLine from the [rufus-scheduler](https://github.com/jmettraux/rufus-scheduler) gem.
|
7
|
+
|
8
|
+
[![Build Status](https://travis-ci.org/bwthomas/whedon.png)](https://travis-ci.org/bwthomas/whedon)
|
7
9
|
|
8
10
|
## API example
|
9
11
|
|
data/lib/whedon/schedule.rb
CHANGED
@@ -27,6 +27,8 @@ require 'tzinfo'
|
|
27
27
|
|
28
28
|
module Whedon
|
29
29
|
|
30
|
+
class ParseError < ArgumentError; end
|
31
|
+
|
30
32
|
#
|
31
33
|
# A 'cron line' is a line in the sense of a crontab
|
32
34
|
# (man 5 crontab) file line.
|
@@ -62,7 +64,7 @@ module Whedon
|
|
62
64
|
@timezone = (TZInfo::Timezone.get(items.last) rescue nil)
|
63
65
|
items.pop if @timezone
|
64
66
|
|
65
|
-
raise
|
67
|
+
raise ParseError.new(
|
66
68
|
"not a valid cronline : '#{line}'"
|
67
69
|
) unless items.length == 5 or items.length == 6
|
68
70
|
|
@@ -77,7 +79,7 @@ module Whedon
|
|
77
79
|
|
78
80
|
[ @seconds, @minutes, @hours, @months ].each do |es|
|
79
81
|
|
80
|
-
raise
|
82
|
+
raise ParseError.new(
|
81
83
|
"invalid cronline: '#{line}'"
|
82
84
|
) if es && es.find { |e| ! e.is_a?(Fixnum) }
|
83
85
|
end
|
@@ -234,7 +236,7 @@ module Whedon
|
|
234
236
|
|
235
237
|
if m = it.match(/^(.+)#(l|-?[12345])$/)
|
236
238
|
|
237
|
-
raise
|
239
|
+
raise ParseError.new(
|
238
240
|
"ranges are not supported for monthdays (#{it})"
|
239
241
|
) if m[1].index('-')
|
240
242
|
|
@@ -247,7 +249,7 @@ module Whedon
|
|
247
249
|
expr = it.dup
|
248
250
|
WEEKDAYS.each_with_index { |a, i| expr.gsub!(/#{a}/, i.to_s) }
|
249
251
|
|
250
|
-
raise
|
252
|
+
raise ParseError.new(
|
251
253
|
"invalid weekday expression (#{it})"
|
252
254
|
) if expr !~ /^0*[0-7](-0*[0-7])?$/
|
253
255
|
|
@@ -269,7 +271,7 @@ module Whedon
|
|
269
271
|
|
270
272
|
r = item.split(',').map { |i| parse_range(i.strip, min, max) }.flatten
|
271
273
|
|
272
|
-
raise
|
274
|
+
raise ParseError.new(
|
273
275
|
"found duplicates in #{item.inspect}"
|
274
276
|
) if raise_error_on_duplicate? && r.uniq.size < r.size
|
275
277
|
|
@@ -284,7 +286,7 @@ module Whedon
|
|
284
286
|
|
285
287
|
m = item.match(RANGE_REGEX)
|
286
288
|
|
287
|
-
raise
|
289
|
+
raise ParseError.new(
|
288
290
|
"cannot parse #{item.inspect}"
|
289
291
|
) unless m
|
290
292
|
|
@@ -298,7 +300,7 @@ module Whedon
|
|
298
300
|
inc = m[3]
|
299
301
|
inc = inc ? inc.to_i : 1
|
300
302
|
|
301
|
-
raise
|
303
|
+
raise ParseError.new(
|
302
304
|
"#{item.inspect} is not in range #{min}..#{max}"
|
303
305
|
) if sta < min or edn > max
|
304
306
|
|
data/lib/whedon/version.rb
CHANGED
@@ -59,7 +59,7 @@ describe Whedon::Schedule do
|
|
59
59
|
|
60
60
|
it 'rejects invalid cronlines' do
|
61
61
|
|
62
|
-
lambda { cl '* nada * * 9' }.should raise_error(
|
62
|
+
lambda { cl '* nada * * 9' }.should raise_error(Whedon::ParseError)
|
63
63
|
end
|
64
64
|
|
65
65
|
it 'interprets cron strings with TZ correctly' do
|
@@ -88,7 +88,7 @@ describe Whedon::Schedule do
|
|
88
88
|
|
89
89
|
lambda {
|
90
90
|
Whedon::Schedule.new('* * * * sun#1-sun#2')
|
91
|
-
}.should raise_error(
|
91
|
+
}.should raise_error(Whedon::ParseError)
|
92
92
|
end
|
93
93
|
|
94
94
|
it 'accepts items with initial 0' do
|
@@ -110,7 +110,7 @@ describe Whedon::Schedule do
|
|
110
110
|
|
111
111
|
it 'raises an error for duplicates when configured to do so' do
|
112
112
|
|
113
|
-
lambda { Ex.new('* * L,L * *') }.should raise_error(
|
113
|
+
lambda { Ex.new('* * L,L * *') }.should raise_error(Whedon::ParseError)
|
114
114
|
end
|
115
115
|
|
116
116
|
it 'interprets cron strings with L correctly' do
|
@@ -122,22 +122,22 @@ describe Whedon::Schedule do
|
|
122
122
|
|
123
123
|
it 'does not support ranges for L' do
|
124
124
|
|
125
|
-
lambda { cl '* * 15-L * *'}.should raise_error(
|
126
|
-
lambda { cl '* * L/4 * *'}.should raise_error(
|
125
|
+
lambda { cl '* * 15-L * *'}.should raise_error(Whedon::ParseError)
|
126
|
+
lambda { cl '* * L/4 * *'}.should raise_error(Whedon::ParseError)
|
127
127
|
end
|
128
128
|
|
129
129
|
it 'raises if L is used for something else than days' do
|
130
130
|
|
131
|
-
lambda { cl '* L * * *'}.should raise_error(
|
131
|
+
lambda { cl '* L * * *'}.should raise_error(Whedon::ParseError)
|
132
132
|
end
|
133
133
|
|
134
134
|
it 'raises for out of range input' do
|
135
135
|
|
136
|
-
lambda { cl '60-62 * * * *'}.should raise_error(
|
137
|
-
lambda { cl '62 * * * *'}.should raise_error(
|
138
|
-
lambda { cl '60 * * * *'}.should raise_error(
|
139
|
-
lambda { cl '* 25-26 * * *'}.should raise_error(
|
140
|
-
lambda { cl '* 25 * * *'}.should raise_error(
|
136
|
+
lambda { cl '60-62 * * * *'}.should raise_error(Whedon::ParseError)
|
137
|
+
lambda { cl '62 * * * *'}.should raise_error(Whedon::ParseError)
|
138
|
+
lambda { cl '60 * * * *'}.should raise_error(Whedon::ParseError)
|
139
|
+
lambda { cl '* 25-26 * * *'}.should raise_error(Whedon::ParseError)
|
140
|
+
lambda { cl '* 25 * * *'}.should raise_error(Whedon::ParseError)
|
141
141
|
#
|
142
142
|
# as reported by Aimee Rose in
|
143
143
|
# https://github.com/jmettraux/rufus-scheduler/pull/58
|
data/whedon.gemspec
CHANGED
@@ -4,7 +4,7 @@ require "whedon/version"
|
|
4
4
|
|
5
5
|
Gem::Specification.new do |s|
|
6
6
|
s.name = "whedon"
|
7
|
-
s.version =
|
7
|
+
s.version = Whedon::VERSION
|
8
8
|
s.platform = Gem::Platform::RUBY
|
9
9
|
s.authors = ["John Mettraux", "Blake Thomas"]
|
10
10
|
s.email = ["jmettraux@gmail.com", "bwthomas@gmail.com"]
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: whedon
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.2
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -86,6 +86,7 @@ extra_rdoc_files: []
|
|
86
86
|
files:
|
87
87
|
- .gitignore
|
88
88
|
- .rspec
|
89
|
+
- .travis.yml
|
89
90
|
- Gemfile
|
90
91
|
- README.md
|
91
92
|
- Rakefile
|