cronos 0.3.1

Sign up to get free protection for your applications and to get access to all the features.
data/CHANGELOG ADDED
@@ -0,0 +1,14 @@
1
+ == 0.3.1 2009-02-03
2
+ - added ranges to #days
3
+
4
+ == 0.3.0 2009-01-27
5
+ - better range handling for #on and #of including support for end excluded ranges
6
+ - aliased #of with #in
7
+ - make #every more flexible to allow use with for days and months eg. every(:thursday, 'Friday') or every(:jan, :feb)
8
+ - adde midnight and midday methods
9
+
10
+ == 0.2.2 2009-01-17
11
+ - fix to ensure string values in hash from to_hash method
12
+
13
+ == 0.2.1 2009-01-17
14
+ - added to_hash method with CronEdit compatible key names
data/LICENSE ADDED
@@ -0,0 +1,20 @@
1
+ Copyright (c) 2008 Adam Meehan
2
+
3
+ Permission is hereby granted, free of charge, to any person obtaining
4
+ a copy of this software and associated documentation files (the
5
+ "Software"), to deal in the Software without restriction, including
6
+ without limitation the rights to use, copy, modify, merge, publish,
7
+ distribute, sublicense, and/or sell copies of the Software, and to
8
+ permit persons to whom the Software is furnished to do so, subject to
9
+ the following conditions:
10
+
11
+ The above copyright notice and this permission notice shall be
12
+ included in all copies or substantial portions of the Software.
13
+
14
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
15
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
16
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
17
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
18
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
19
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
20
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
data/README.rdoc ADDED
@@ -0,0 +1,73 @@
1
+ = Cronos
2
+
3
+ A Ruby DSL for outputting Cron intervals.
4
+
5
+ Using a natural syntax to write cron task intervals assists in generating the correct cron interval
6
+ you are after instead of trying to remember the cron syntax and conventions.
7
+
8
+
9
+ == Examples
10
+
11
+ cron = Cronos::Interval
12
+
13
+ cron.new.hourly.to_s
14
+ # => '0 * * * *'
15
+
16
+ cron.new.daily.to_s
17
+ # => '0 0 * * *'
18
+
19
+ cron.new.weekly.to_s
20
+ # => '0 0 * * 0'
21
+
22
+ cron.new.weekdays.at(12.30).to_s
23
+ # => '30 12 * * 1-5'
24
+
25
+ cron.new.weekends.at(12.30).to_s
26
+ # => '30 12 * * 0,6'
27
+
28
+ cron.new.at('1.30pm').daily.to_s
29
+ # => '30 13 * * *'
30
+
31
+ cron.new.every(6).hours.on('15th').of(:january).to_s
32
+ # => '0 0,6,12,18 15 1 *'
33
+
34
+ cron.new.every(20).minutes.on(15..18).of(:jan, :feb, :mar).to_s
35
+ # => '0,20,40 * 15-18 1,2,3 *'
36
+
37
+ cron.new.at(14.45).on_days(:monday, :tuesday).to_s
38
+ # => '45 14 * * 1,2'
39
+
40
+ == Caveats
41
+
42
+ Certain combinations produce unintuitive results. They should be obvious but just in case I will
43
+ list some. Such as
44
+
45
+ weekly.on_days(:monday, :tuesday)
46
+
47
+ Will actually run the task *twice* weekly
48
+
49
+ TODO: more weird stuff?
50
+
51
+ Also cron itself allows days of month and days of week to be set. These are independent of each other.
52
+
53
+ For example:
54
+
55
+ on_the('15th').of(:jan).on_days(:mon, :tue)
56
+
57
+ This will be run on the 15th of January AND every Monday and Tuesday of January, so be aware. Though it
58
+ is a strange combination anyway, the result is the union of both and not the intersection.
59
+
60
+
61
+ == Install
62
+
63
+ sudo gem install adzap-cronos -s http://gems.github.com
64
+
65
+
66
+ == Credits
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/Rakefile ADDED
@@ -0,0 +1,58 @@
1
+ require 'rubygems'
2
+ require 'rake/gempackagetask'
3
+ require 'rubygems/specification'
4
+ require 'date'
5
+ require 'spec/rake/spectask'
6
+ require 'lib/cronos'
7
+
8
+ GEM = "cronos"
9
+ GEM_VERSION = Cronos::VERSION
10
+ AUTHOR = "Adam Meehan"
11
+ EMAIL = "adam.meehan@gmail.com"
12
+ HOMEPAGE = "http://github.com/adzap/cronos"
13
+ SUMMARY = "Tool for generating cron intervals using a natural syntax"
14
+
15
+ spec = Gem::Specification.new do |s|
16
+ s.name = GEM
17
+ s.version = GEM_VERSION
18
+ s.platform = Gem::Platform::RUBY
19
+ s.has_rdoc = true
20
+ s.extra_rdoc_files = ["README.rdoc", "LICENSE", 'TODO', "CHANGELOG"]
21
+ s.summary = SUMMARY
22
+ s.description = s.summary
23
+ s.author = AUTHOR
24
+ s.email = EMAIL
25
+ s.homepage = HOMEPAGE
26
+
27
+ # Uncomment this to add a dependency
28
+ # s.add_dependency "foo"
29
+
30
+ s.require_path = 'lib'
31
+ s.autorequire = GEM
32
+ s.files = %w(LICENSE README.rdoc Rakefile TODO CHANGELOG) + Dir.glob("{lib,spec}/**/*")
33
+ end
34
+
35
+ task :default => :spec
36
+
37
+ desc "Run specs"
38
+ Spec::Rake::SpecTask.new do |t|
39
+ t.spec_files = FileList['spec/**/*_spec.rb']
40
+ t.spec_opts = %w(-fs --color)
41
+ end
42
+
43
+
44
+ Rake::GemPackageTask.new(spec) do |pkg|
45
+ pkg.gem_spec = spec
46
+ end
47
+
48
+ desc "install the gem locally"
49
+ task :install => [:package] do
50
+ sh %{sudo gem install pkg/#{GEM}-#{GEM_VERSION}}
51
+ end
52
+
53
+ desc "create a gemspec file"
54
+ task :make_spec do
55
+ File.open("#{GEM}.gemspec", "w") do |file|
56
+ file.puts spec.to_ruby
57
+ end
58
+ end
data/TODO ADDED
@@ -0,0 +1,3 @@
1
+ TODO:
2
+ - more examples
3
+ - more everything as its a start
data/lib/cronos.rb ADDED
@@ -0,0 +1,261 @@
1
+ module Cronos
2
+
3
+ VERSION = '0.3.1'
4
+
5
+ class Interval
6
+ attr_accessor :min, :hour, :day, :month, :dow
7
+
8
+ MONTHS = [:jan, :feb, :mar, :apr, :may, :jun, :jul, :aug, :sep, :oct, :nov, :dec]
9
+
10
+ DAYS = [:sun, :mon, :tue, :wed, :thu, :fri, :sat]
11
+
12
+ # Time:
13
+ # at(12)
14
+ # at(1.30)
15
+ # at('01.30')
16
+ # at(14.30)
17
+ # at('2pm')
18
+ #
19
+ def at(time)
20
+ @hour, @min, meridian = parse_time(time)
21
+
22
+ raise "invalid hour value for 'at'" if @hour > 12 && meridian
23
+ raise "invalid minute value for 'at'" if @min > 59
24
+
25
+ case meridian
26
+ when 'am': @hour = 0 if @hour == 12
27
+ when 'pm': @hour += 12 if @hour < 12
28
+ end
29
+ raise "invalid hour value for 'at'" if @hour > 23
30
+ self
31
+ end
32
+
33
+ # Repeats an interval:
34
+ # every(10).minutes
35
+ # every(6).hours
36
+ # every(2).months
37
+ #
38
+ # or use as an alias for #on or #days
39
+ # every(:monday)
40
+ # every('February', :march)
41
+ #
42
+ def every(*multiple)
43
+ return RepeatInterval.new(multiple.first, self) if multiple.first.is_a?(Fixnum)
44
+
45
+ abbrs = multiple.map {|i| i.to_s.downcase[0..2].to_sym }
46
+
47
+ if abbrs.all? {|abbr| MONTHS.include?(abbr) }
48
+ of(*abbrs)
49
+ elsif abbrs.all? {|abbr| DAYS.include?(abbr) }
50
+ days(*abbrs)
51
+ else
52
+ raise "Unknown interval type passed to #every"
53
+ end
54
+ end
55
+
56
+ # Days of month:
57
+ # on(13)
58
+ # on('13th')
59
+ # on(13..17)
60
+ # on(13...18)
61
+ # on_the('13th')
62
+ #
63
+ def on(*args)
64
+ if args.first.is_a?(Range)
65
+ @day = format_range(args.first)
66
+ else
67
+ list = args.collect {|day| day.to_s.to_i }
68
+ @day = list.join(',')
69
+ end
70
+ self
71
+ end
72
+ alias on_the on
73
+
74
+ # Days of the week:
75
+ # days(:monday)
76
+ # days('Monday')
77
+ # days(:mon)
78
+ # days(1..3)
79
+ # days(1...4)
80
+ # on_day(:monday)
81
+ # days(:mon, :tues)
82
+ # on_days(:mon, :tues)
83
+ #
84
+ def days(*args)
85
+ if args.first.is_a?(Range)
86
+ @dow = format_range(args.first)
87
+ else
88
+ list = args.map {|day| DAYS.index(day.to_s.downcase[0..2].to_sym) }
89
+ @dow = list.join(',')
90
+ end
91
+ self
92
+ end
93
+ alias on_days days
94
+ alias on_day days
95
+
96
+ # Months:
97
+ # of(:january)
98
+ # of('January')
99
+ # of(:jan)
100
+ # of(:jan, :feb, :mar)
101
+ # of(1..3)
102
+ # of(1...4)
103
+ # of_months(1, 2, 3)
104
+ # in(:january)
105
+ #
106
+ def of(*args)
107
+ if args.first.is_a?(Range)
108
+ @month = format_range(args.first)
109
+ else
110
+ list = args.map {|month| MONTHS.index(month.to_s.downcase[0..2].to_sym) + 1 unless month.is_a?(Fixnum) }
111
+ @month = list.join(',')
112
+ end
113
+ self
114
+ end
115
+ alias of_months of
116
+ alias in of
117
+
118
+ def hourly
119
+ @min = 0
120
+ @hour = nil
121
+ self
122
+ end
123
+
124
+ def daily
125
+ @min ||= 0
126
+ @hour ||= 0
127
+ @day = nil
128
+ self
129
+ end
130
+ alias once_a_day daily
131
+
132
+ def midnight
133
+ @min = 0
134
+ @hour = 0
135
+ self
136
+ end
137
+ alias at_midnight midnight
138
+
139
+ def midday
140
+ @min = 0
141
+ @hour = 12
142
+ self
143
+ end
144
+ alias at_midday midday
145
+
146
+ def weekly
147
+ @min ||= 0
148
+ @hour ||= 0
149
+ @dow ||= 0
150
+ @day = nil
151
+ @month = nil
152
+ self
153
+ end
154
+ alias once_a_week weekly
155
+
156
+ def monthly
157
+ @min ||= 0
158
+ @hour ||= 0
159
+ @day ||= 1
160
+ @month = nil
161
+ @dow = nil
162
+ self
163
+ end
164
+ alias once_a_month monthly
165
+
166
+ def weekdays
167
+ @min ||= 0
168
+ @hour ||= 0
169
+ @dow = '1-5'
170
+ self
171
+ end
172
+
173
+ def weekends
174
+ @min ||= 0
175
+ @hour ||= 0
176
+ @dow = '0,6'
177
+ self
178
+ end
179
+
180
+ def to_s
181
+ "#{min || '*'} #{hour || '*'} #{day || '*'} #{month || '*'} #{dow || '*'}"
182
+ end
183
+
184
+ def to_hash
185
+ {
186
+ :minute => "#{min || '*'}",
187
+ :hour => "#{hour || '*'}",
188
+ :day => "#{day || '*'}",
189
+ :month => "#{month || '*'}",
190
+ :weekday => "#{dow || '*'}"
191
+ }
192
+ end
193
+
194
+ private
195
+
196
+ def parse_time(time)
197
+ meridian = /pm|am/i.match(time.to_s)[0].downcase rescue nil
198
+ hour, min = *time.to_s.split('.')
199
+
200
+ hour = hour.to_i
201
+ min = min.strip.ljust(2, '0').to_i if min
202
+ min ||= 0
203
+
204
+ return hour, min, meridian
205
+ end
206
+
207
+ def format_range(range)
208
+ list = Array(range).sort
209
+ "#{list.first}-#{list.last}"
210
+ end
211
+
212
+ class RepeatInterval
213
+
214
+ def initialize(multiple, interval)
215
+ @multiple, @interval = multiple, interval
216
+ end
217
+
218
+ def minutes
219
+ raise 'Multiple of minutes will not fit into an hour' if (60 % @multiple) > 0
220
+ calculate_intervals(60)
221
+ @interval.min = self
222
+ @interval
223
+ end
224
+
225
+ def hours
226
+ raise 'Multiple of hours will not fit into a day' if (24 % @multiple) > 0
227
+ calculate_intervals(24)
228
+ @interval.min = 0
229
+ @interval.hour = self
230
+ @interval
231
+ end
232
+
233
+ def months
234
+ raise 'Multiple of months will not fit into a year' if (12 % @multiple) > 0
235
+ calculate_intervals(12, 1)
236
+ @interval.min ||= 0
237
+ @interval.hour ||= 0
238
+ @interval.day ||= 1
239
+ @interval.month = self
240
+ @interval
241
+ end
242
+
243
+ def calculate_intervals(base, initial = 0)
244
+ repeats = (base / @multiple) - 1
245
+ set = [initial]
246
+ 1.upto(repeats) {|factor| set << (factor * @multiple + initial) }
247
+ @intervals = set
248
+ end
249
+
250
+ def to_s
251
+ @intervals.join(',')
252
+ end
253
+
254
+ def to_a
255
+ @intervals
256
+ end
257
+ end
258
+
259
+ end
260
+
261
+ end
@@ -0,0 +1,329 @@
1
+ require File.dirname(__FILE__) + '/spec_helper'
2
+
3
+ describe Cronos::Interval do
4
+
5
+ it "should return default interval for every minute" do
6
+ interval.to_s.should == '* * * * *'
7
+ end
8
+
9
+ it "should return hash of values from to_hash method" do
10
+ interval.at(2.01).on_the('3rd').of(:april).to_hash.should == {:minute => '1', :hour => '2', :day => '3', :month => '4', :weekday => '*'}
11
+ end
12
+
13
+ describe "at method" do
14
+ it "should output interval from integer with hour as integer value and 0 minute" do
15
+ interval.at(8).to_s.should == '0 8 * * *'
16
+ end
17
+
18
+ it "should output interval from a float with hour value from integer part and minute from decimal part" do
19
+ interval.at(8.21).to_s.should == '21 8 * * *'
20
+ end
21
+
22
+ it "should output interval from a float with hour value from integer part and minute from decimal part left justified to 2 digits" do
23
+ interval.at(8.20).to_s.should == '20 8 * * *'
24
+ end
25
+
26
+ it "should output interval from time string with pm meridian having hour adjusted 24 hour time" do
27
+ interval.at('8.21pm').to_s.should == '21 20 * * *'
28
+ end
29
+
30
+ it "should output interval from time string with pm meridian having hour unadjusted if hour is 12" do
31
+ interval.at('12.21pm').to_s.should == '21 12 * * *'
32
+ end
33
+
34
+ it "should output interval from time string with am meridian having hour adjusted to 0 if hour is 12" do
35
+ interval.at('12.21am').to_s.should == '21 0 * * *'
36
+ end
37
+
38
+ it "should raise error if hours out of range" do
39
+ lambda { interval.daily.at('24.21') }.should raise_error
40
+ end
41
+
42
+ it "should raise error if minutes out of range" do
43
+ lambda { interval.daily.at('23.60') }.should raise_error
44
+ end
45
+ end
46
+
47
+ describe "on method" do
48
+ it "should output interval from integer with day of month as value" do
49
+ interval.on(15).to_s.should == '* * 15 * *'
50
+ end
51
+
52
+ it "should output interval from day string with ordinal suffix" do
53
+ interval.on('15th').to_s.should == '* * 15 * *'
54
+ end
55
+
56
+ it "should output interval from inclusive range as dashed day of month range " do
57
+ interval.on(15..17).to_s.should == '* * 15-17 * *'
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
63
+
64
+ it "should output interval from integer array as day number list" do
65
+ interval.on(15, 16, 17).to_s.should == '* * 15,16,17 * *'
66
+ end
67
+
68
+ it "should output interval from day string array as day number list" do
69
+ interval.on('15th', '16th', '17th').to_s.should == '* * 15,16,17 * *'
70
+ end
71
+ end
72
+
73
+ describe "of method" do
74
+ it "should output interval with month number from a symbol month name" do
75
+ interval.of(:january).to_s.should == '* * * 1 *'
76
+ end
77
+
78
+ it "should output interval with month number from a symbol short month name" do
79
+ interval.of(:jan).to_s.should == '* * * 1 *'
80
+ end
81
+
82
+ it "should output interval with month number from a strong month name" do
83
+ interval.of('January').to_s.should == '* * * 1 *'
84
+ end
85
+
86
+ it "should output interval with comma seperated month numbers from array of symbol month names" do
87
+ interval.of(:january, :february, :march).to_s.should == '* * * 1,2,3 *'
88
+ end
89
+
90
+ it "should output interval with comma seperated month numbers from array of short symbol month names" do
91
+ interval.of(:jan, :feb, :mar).to_s.should == '* * * 1,2,3 *'
92
+ end
93
+
94
+ it "should output interval with comma seperated month numbers from array of string month names" do
95
+ interval.of('January', 'February', 'March').to_s.should == '* * * 1,2,3 *'
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
105
+ end
106
+
107
+ describe "days method" do
108
+ it "should output interval with day number from a symbol day name" do
109
+ interval.days(:monday).to_s.should == '* * * * 1'
110
+ end
111
+
112
+ it "should output interval with day number from a string day name" do
113
+ interval.days('Mondays').to_s.should == '* * * * 1'
114
+ end
115
+
116
+ it "should output interval with day number from a symbol short day name" do
117
+ interval.days(:mon).to_s.should == '* * * * 1'
118
+ end
119
+
120
+ it "should output interval with day numbers from array of symbol day names" do
121
+ interval.days(:monday, :wednesday, :friday).to_s.should == '* * * * 1,3,5'
122
+ end
123
+
124
+ it "should output interval with day numbers from array of symbol short day names" do
125
+ interval.days(:mon, :wed, :fri).to_s.should == '* * * * 1,3,5'
126
+ end
127
+
128
+ it "should output interval with day numbers from array of string day names" do
129
+ interval.days('Monday', 'Wednesday', 'Friday').to_s.should == '* * * * 1,3,5'
130
+ end
131
+
132
+ it "should output interval from integer inclusive range as dashed dow range " do
133
+ interval.days(1..3).to_s.should == '* * * * 1-3'
134
+ end
135
+
136
+ it "should output interval from integer exclusive range as dashed dow range " do
137
+ interval.days(1...4).to_s.should == '* * * * 1-3'
138
+ end
139
+ end
140
+
141
+ describe "hourly method" do
142
+ it "should output interval to run at start of every hour" do
143
+ interval.hourly.to_s.should == '0 * * * *'
144
+ end
145
+
146
+ it "should only affect the hour and minutes" do
147
+ interval.day = 1
148
+ interval.month = 1
149
+ interval.dow = 1
150
+ interval.hourly.to_s.should == '0 * 1 1 1'
151
+ end
152
+ end
153
+
154
+ describe "daily method" do
155
+ it "should output interval to run at 00:00 every day by default" do
156
+ interval.daily.to_s.should == '0 0 * * *'
157
+ end
158
+
159
+ it "should only affect the hour, minutes and day" do
160
+ interval.month = 1
161
+ interval.dow = 1
162
+ interval.daily.to_s.should == '0 0 * 1 1'
163
+ end
164
+
165
+ it "should preserve hour and minutes if set" do
166
+ interval.min = 10
167
+ interval.hour = 11
168
+ interval.daily.to_s.should == '10 11 * * *'
169
+ end
170
+ end
171
+
172
+ describe "midnight method" do
173
+ it "should output interval to run at 00:00" do
174
+ interval.midnight.to_s.should == '0 0 * * *'
175
+ end
176
+ end
177
+
178
+ describe "midday method" do
179
+ it "should output interval to run at 12:00" do
180
+ interval.midday.to_s.should == '0 12 * * *'
181
+ end
182
+ end
183
+
184
+ describe "weekly method" do
185
+ it "should output interval to run on Sunday at 00:00 by default" do
186
+ interval.weekly.to_s.should == '0 0 * * 0'
187
+ end
188
+
189
+ it "should override day of month and month" do
190
+ interval.day = 1
191
+ interval.month = 1
192
+ interval.weekly.to_s.should == '0 0 * * 0'
193
+ end
194
+
195
+ it "should preserve hour, minute and day of week if set" do
196
+ interval.min = 10
197
+ interval.hour = 11
198
+ interval.dow = 1
199
+ interval.daily.to_s.should == '10 11 * * 1'
200
+ end
201
+ end
202
+
203
+ describe "monthly method" do
204
+ it "should output interval to run on the 1st day of every month at 00:00 by default" do
205
+ interval.monthly.to_s.should == '0 0 1 * *'
206
+ end
207
+
208
+ it "should override day of month and month" do
209
+ interval.day = 1
210
+ interval.month = 1
211
+ interval.monthly.to_s.should == '0 0 1 * *'
212
+ end
213
+
214
+ it "should preserve hour, minute and day if set" do
215
+ interval.min = 10
216
+ interval.hour = 11
217
+ interval.day = 12
218
+ interval.monthly.to_s.should == '10 11 12 * *'
219
+ end
220
+ end
221
+
222
+ describe "weekends method" do
223
+ it "should output interval to run at 00:00 every Saturday and Sunday" do
224
+ interval.weekends.to_s.should == '0 0 * * 0,6'
225
+ end
226
+ end
227
+
228
+ describe "weekdays method" do
229
+ it "should output interval to run at 00:00 every day Monday to Friday" do
230
+ interval.weekdays.to_s.should == '0 0 * * 1-5'
231
+ end
232
+ end
233
+
234
+ describe "every(x).minutes" do
235
+ it "should output interval for list of minutes differing by arg value" do
236
+ interval.every(15).minutes.to_s.should == '0,15,30,45 * * * *'
237
+ end
238
+
239
+ it "should raise error if x not a divisor of 60" do
240
+ lambda { interval.every(13).minutes }.should raise_error
241
+ end
242
+ end
243
+
244
+ describe "every(x).hours" do
245
+ it "should output interval for 0 minute and list of hours differing by arg value" do
246
+ interval.every(6).hours.to_s.should == '0 0,6,12,18 * * *'
247
+ end
248
+
249
+ it "should raise error if x not a divisor of 24" do
250
+ lambda { interval.every(13).minutes }.should raise_error
251
+ end
252
+ end
253
+
254
+ describe "every(x).months" do
255
+ it "should output interval for 00:00 on 1st day of month and list of months differing by arg value" do
256
+ interval.every(6).hours.to_s.should == '0 0,6,12,18 * * *'
257
+ end
258
+
259
+ it "should raise error if x not a divisor of 12" do
260
+ lambda { interval.every(7).minutes }.should raise_error
261
+ end
262
+ end
263
+
264
+ describe "every(day_name)" do
265
+ it "should output interval for day symbol as day of week" do
266
+ interval.every(:sunday).to_s.should == '* * * * 0'
267
+ end
268
+
269
+ it "should output interval for list of days as days of week" do
270
+ interval.every(:thursay, 'Friday').to_s.should == '* * * * 4,5'
271
+ end
272
+ end
273
+
274
+ describe "every(month_name)" do
275
+ it "should output interval for month symbol as month" do
276
+ interval.every(:january).to_s.should == '* * * 1 *'
277
+ end
278
+
279
+ it "should output interval for list of months as months" do
280
+ interval.every(:february, 'March').to_s.should == '* * * 2,3 *'
281
+ end
282
+ end
283
+
284
+ describe "combinations" do
285
+ it "weekly.at(3.30) should output '30 3 * * 0'" do
286
+ interval.weekly.at(3.30).to_s.should == '30 3 * * 0'
287
+ end
288
+
289
+ it "monthly.at(3.30) should output '30 3 * * *'" do
290
+ interval.monthly.at(3.30).to_s.should == '30 3 1 * *'
291
+ end
292
+
293
+ it "monthly.on_the('15th').at(3.30) should output '30 3 15 * *'" do
294
+ interval.monthly.on_the('15th').at(3.30).to_s.should == '30 3 15 * *'
295
+ end
296
+
297
+ it "at('11pm').on_days(:monday, :tuesday) should output '0 11 * * 1,2'" do
298
+ interval.at('11pm').on_days(:monday, :tuesday).to_s.should == '0 23 * * 1,2'
299
+ end
300
+
301
+ it "on(15).of(:january) should output '* * 15 1 *'" do
302
+ interval.on(15).of(:january).to_s.should == '* * 15 1 *'
303
+ end
304
+
305
+ it "on(15, 16, 17).of(:january) should output '* * 15,16,17 1 *'" do
306
+ interval.on(15, 16, 17).of(:january).to_s.should == '* * 15,16,17 1 *'
307
+ end
308
+
309
+ it "on(15..17).of(:january) should output '* * 15-17 1 *'" do
310
+ interval.on(15..17).of(:january).to_s.should == '* * 15-17 1 *'
311
+ end
312
+
313
+ it "on(15, 16, 17).of(:january) should output '* * 15 1,6,12 *'" do
314
+ interval.on(15).of(:jan, :jun, :dec).to_s.should == '* * 15 1,6,12 *'
315
+ end
316
+
317
+ it "at('2.13pm').on_the_('15th').of(:january) should output '13 14 15 1'" do
318
+ interval.at('2.13pm').on_the(15).of(:january).to_s.should == '13 14 15 1 *'
319
+ end
320
+
321
+ it "every(15).minutes.on_the('15th').of(:january) should output '0,15,30,45 * 15 1 *'" do
322
+ interval.every(15).minutes.on_the('15th').of(:january).to_s.should == '0,15,30,45 * 15 1 *'
323
+ end
324
+ end
325
+
326
+ def interval
327
+ @interval ||= Cronos::Interval.new
328
+ end
329
+ end
@@ -0,0 +1,6 @@
1
+ $TESTING=true
2
+ $:.push File.join(File.dirname(__FILE__), '..', 'lib')
3
+
4
+ require 'rubygems'
5
+ require 'spec'
6
+ require 'cronos'
metadata ADDED
@@ -0,0 +1,63 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: cronos
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.3.1
5
+ platform: ruby
6
+ authors:
7
+ - Adam Meehan
8
+ autorequire: cronos
9
+ bindir: bin
10
+ cert_chain: []
11
+
12
+ date: 2009-02-03 00:00:00 +11:00
13
+ default_executable:
14
+ dependencies: []
15
+
16
+ description: Tool for generating cron intervals using a natural syntax
17
+ email: adam.meehan@gmail.com
18
+ executables: []
19
+
20
+ extensions: []
21
+
22
+ extra_rdoc_files:
23
+ - README.rdoc
24
+ - LICENSE
25
+ - TODO
26
+ - CHANGELOG
27
+ files:
28
+ - LICENSE
29
+ - README.rdoc
30
+ - Rakefile
31
+ - TODO
32
+ - CHANGELOG
33
+ - lib/cronos.rb
34
+ - spec/spec_helper.rb
35
+ - spec/cronos_spec.rb
36
+ has_rdoc: true
37
+ homepage: http://github.com/adzap/cronos
38
+ post_install_message:
39
+ rdoc_options: []
40
+
41
+ require_paths:
42
+ - lib
43
+ required_ruby_version: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - ">="
46
+ - !ruby/object:Gem::Version
47
+ version: "0"
48
+ version:
49
+ required_rubygems_version: !ruby/object:Gem::Requirement
50
+ requirements:
51
+ - - ">="
52
+ - !ruby/object:Gem::Version
53
+ version: "0"
54
+ version:
55
+ requirements: []
56
+
57
+ rubyforge_project:
58
+ rubygems_version: 1.3.1
59
+ signing_key:
60
+ specification_version: 2
61
+ summary: Tool for generating cron intervals using a natural syntax
62
+ test_files: []
63
+