adzap-cronos 0.2.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- data/CHANGELOG +6 -0
- data/README.rdoc +6 -0
- data/lib/cronos.rb +46 -9
- data/spec/cronos_spec.rb +45 -1
- metadata +1 -1
data/CHANGELOG
CHANGED
@@ -1,3 +1,9 @@
|
|
1
|
+
== 0.3.0 2009-01-27
|
2
|
+
- better range handling for #on and #of including support for end excluded ranges
|
3
|
+
- aliased #of with #in
|
4
|
+
- make #every more flexible to allow use with for days and months eg. every(:thursday, 'Friday') or every(:jan, :feb)
|
5
|
+
- adde midnight and midday methods
|
6
|
+
|
1
7
|
== 0.2.2 2009-01-17
|
2
8
|
- fix to ensure string values in hash from to_hash method
|
3
9
|
|
data/README.rdoc
CHANGED
@@ -62,6 +62,12 @@ is a strange combination anyway, the result is the union of both and not the int
|
|
62
62
|
|
63
63
|
sudo gem install adzap-cronos -s http://gems.github.com
|
64
64
|
|
65
|
+
|
65
66
|
== Credits
|
66
67
|
|
67
68
|
Adam Meehan (http://duckpunching.com, adam.meehan@gmail.com)
|
69
|
+
|
70
|
+
|
71
|
+
== License
|
72
|
+
|
73
|
+
Copyright (c) 2008 Adam Meehan, released under the MIT license
|
data/lib/cronos.rb
CHANGED
@@ -33,8 +33,22 @@ module Cronos
|
|
33
33
|
# every(6).hours
|
34
34
|
# every(2).months
|
35
35
|
#
|
36
|
-
|
37
|
-
|
36
|
+
# or use as an alias for #on or #days
|
37
|
+
# every(:monday)
|
38
|
+
# every('February', :march)
|
39
|
+
#
|
40
|
+
def every(*multiple)
|
41
|
+
return RepeatInterval.new(multiple.first, self) if multiple.first.is_a?(Fixnum)
|
42
|
+
|
43
|
+
abbrs = multiple.map {|i| i.to_s.downcase[0..2].to_sym }
|
44
|
+
|
45
|
+
if abbrs.all? {|abbr| MONTHS.include?(abbr) }
|
46
|
+
of(*abbrs)
|
47
|
+
elsif abbrs.all? {|abbr| DAYS.include?(abbr) }
|
48
|
+
days(*abbrs)
|
49
|
+
else
|
50
|
+
raise "Unknown interval type passed to #every"
|
51
|
+
end
|
38
52
|
end
|
39
53
|
|
40
54
|
# Days of month:
|
@@ -45,12 +59,12 @@ module Cronos
|
|
45
59
|
#
|
46
60
|
def on(*args)
|
47
61
|
if args.first.is_a?(Range)
|
48
|
-
|
49
|
-
@day = "#{
|
62
|
+
list = Array(args.first)
|
63
|
+
@day = "#{list.first}-#{list.last}"
|
50
64
|
else
|
51
65
|
list = args.collect {|day| day.to_s.to_i }
|
52
66
|
@day = list.join(',')
|
53
|
-
end
|
67
|
+
end
|
54
68
|
self
|
55
69
|
end
|
56
70
|
alias on_the on
|
@@ -74,16 +88,25 @@ module Cronos
|
|
74
88
|
# Months:
|
75
89
|
# of(:january)
|
76
90
|
# of('January')
|
77
|
-
# of(:jan
|
91
|
+
# of(:jan)
|
78
92
|
# of(:jan, :feb, :mar)
|
93
|
+
# of(1..3)
|
94
|
+
# of(1...4)
|
79
95
|
# of_months(1, 2, 3)
|
96
|
+
# in(:january)
|
80
97
|
#
|
81
98
|
def of(*args)
|
82
|
-
|
83
|
-
|
99
|
+
if args.first.is_a?(Range)
|
100
|
+
list = Array(args.first)
|
101
|
+
@month = "#{list.first}-#{list.last}"
|
102
|
+
else
|
103
|
+
list = args.map {|month| MONTHS.index(month.to_s.downcase[0..2].to_sym) + 1 unless month.is_a?(Fixnum) }
|
104
|
+
@month = list.join(',')
|
105
|
+
end
|
84
106
|
self
|
85
107
|
end
|
86
108
|
alias of_months of
|
109
|
+
alias in of
|
87
110
|
|
88
111
|
def hourly
|
89
112
|
@min = 0
|
@@ -99,6 +122,20 @@ module Cronos
|
|
99
122
|
end
|
100
123
|
alias once_a_day daily
|
101
124
|
|
125
|
+
def midnight
|
126
|
+
@min = 0
|
127
|
+
@hour = 0
|
128
|
+
self
|
129
|
+
end
|
130
|
+
alias at_midnight midnight
|
131
|
+
|
132
|
+
def midday
|
133
|
+
@min = 0
|
134
|
+
@hour = 12
|
135
|
+
self
|
136
|
+
end
|
137
|
+
alias at_midday midday
|
138
|
+
|
102
139
|
def weekly
|
103
140
|
@min ||= 0
|
104
141
|
@hour ||= 0
|
@@ -205,7 +242,7 @@ module Cronos
|
|
205
242
|
def to_a
|
206
243
|
@intervals
|
207
244
|
end
|
208
|
-
end
|
245
|
+
end
|
209
246
|
|
210
247
|
end
|
211
248
|
|
data/spec/cronos_spec.rb
CHANGED
@@ -53,9 +53,13 @@ describe Cronos::Interval do
|
|
53
53
|
interval.on('15th').to_s.should == '* * 15 * *'
|
54
54
|
end
|
55
55
|
|
56
|
-
it "should output interval from
|
56
|
+
it "should output interval from inclusive range as dashed day of month range " do
|
57
57
|
interval.on(15..17).to_s.should == '* * 15-17 * *'
|
58
58
|
end
|
59
|
+
|
60
|
+
it "should output interval from exclusive range as dashed day of month range " do
|
61
|
+
interval.on(15...18).to_s.should == '* * 15-17 * *'
|
62
|
+
end
|
59
63
|
|
60
64
|
it "should output interval from integer array as day number list" do
|
61
65
|
interval.on(15, 16, 17).to_s.should == '* * 15,16,17 * *'
|
@@ -90,6 +94,14 @@ describe Cronos::Interval do
|
|
90
94
|
it "should output interval with comma seperated month numbers from array of string month names" do
|
91
95
|
interval.of('January', 'February', 'March').to_s.should == '* * * 1,2,3 *'
|
92
96
|
end
|
97
|
+
|
98
|
+
it "should output interval from integer inclusive range as dashed month range " do
|
99
|
+
interval.of(1..3).to_s.should == '* * * 1-3 *'
|
100
|
+
end
|
101
|
+
|
102
|
+
it "should output interval from integer exclusive range as dashed month range " do
|
103
|
+
interval.of(1...4).to_s.should == '* * * 1-3 *'
|
104
|
+
end
|
93
105
|
end
|
94
106
|
|
95
107
|
describe "days method" do
|
@@ -149,6 +161,18 @@ describe Cronos::Interval do
|
|
149
161
|
end
|
150
162
|
end
|
151
163
|
|
164
|
+
describe "midnight method" do
|
165
|
+
it "should output interval to run at 00:00" do
|
166
|
+
interval.midnight.to_s.should == '0 0 * * *'
|
167
|
+
end
|
168
|
+
end
|
169
|
+
|
170
|
+
describe "midday method" do
|
171
|
+
it "should output interval to run at 12:00" do
|
172
|
+
interval.midday.to_s.should == '0 12 * * *'
|
173
|
+
end
|
174
|
+
end
|
175
|
+
|
152
176
|
describe "weekly method" do
|
153
177
|
it "should output interval to run on Sunday at 00:00 by default" do
|
154
178
|
interval.weekly.to_s.should == '0 0 * * 0'
|
@@ -229,6 +253,26 @@ describe Cronos::Interval do
|
|
229
253
|
end
|
230
254
|
end
|
231
255
|
|
256
|
+
describe "every(day_name)" do
|
257
|
+
it "should output interval for day symbol as day of week" do
|
258
|
+
interval.every(:sunday).to_s.should == '* * * * 0'
|
259
|
+
end
|
260
|
+
|
261
|
+
it "should output interval for list of days as days of week" do
|
262
|
+
interval.every(:thursay, 'Friday').to_s.should == '* * * * 4,5'
|
263
|
+
end
|
264
|
+
end
|
265
|
+
|
266
|
+
describe "every(month_name)" do
|
267
|
+
it "should output interval for month symbol as month" do
|
268
|
+
interval.every(:january).to_s.should == '* * * 1 *'
|
269
|
+
end
|
270
|
+
|
271
|
+
it "should output interval for list of months as months" do
|
272
|
+
interval.every(:february, 'March').to_s.should == '* * * 2,3 *'
|
273
|
+
end
|
274
|
+
end
|
275
|
+
|
232
276
|
describe "combinations" do
|
233
277
|
it "weekly.at(3.30) should output '30 3 * * 0'" do
|
234
278
|
interval.weekly.at(3.30).to_s.should == '30 3 * * 0'
|