cron-spec 0.1.0
Sign up to get free protection for your applications and to get access to all the features.
- data/.document +5 -0
- data/.idea/.name +1 -0
- data/.idea/.rakeTasks +7 -0
- data/.idea/cron-spec.iml +40 -0
- data/.idea/encodings.xml +5 -0
- data/.idea/misc.xml +8 -0
- data/.idea/modules.xml +9 -0
- data/.idea/vcs.xml +7 -0
- data/.idea/workspace.xml +347 -0
- data/.rspec +1 -0
- data/.rvmrc +6 -0
- data/Gemfile +13 -0
- data/Gemfile.lock +28 -0
- data/LICENSE.txt +20 -0
- data/README.rdoc +19 -0
- data/Rakefile +50 -0
- data/VERSION +1 -0
- data/cron-spec.gemspec +94 -0
- data/lib/cron-spec.rb +12 -0
- data/lib/cron-spec/cron_specification.rb +70 -0
- data/lib/cron-spec/cron_specification_factory.rb +39 -0
- data/lib/cron-spec/cron_value_base.rb +19 -0
- data/lib/cron-spec/day_factory.rb +12 -0
- data/lib/cron-spec/dow_factory.rb +33 -0
- data/lib/cron-spec/hour_factory.rb +16 -0
- data/lib/cron-spec/minute_factory.rb +16 -0
- data/lib/cron-spec/month_factory.rb +32 -0
- data/lib/cron-spec/range_cron_value.rb +23 -0
- data/lib/cron-spec/single_value_cron_value.rb +21 -0
- data/lib/cron-spec/step_cron_value.rb +21 -0
- data/lib/cron-spec/wildcard_cron_value.rb +15 -0
- data/spec/cron_specification_spec.rb +119 -0
- data/spec/range_cron_value_spec.rb +18 -0
- data/spec/single_value_cron_value_spec.rb +18 -0
- data/spec/spec_helper.rb +12 -0
- data/spec/step_cron_value_spec.rb +17 -0
- data/spec/wildcard_cron_value_spec.rb +13 -0
- metadata +164 -0
@@ -0,0 +1,32 @@
|
|
1
|
+
module CronSpec
|
2
|
+
class MonthFactory < CronSpecificationFactory
|
3
|
+
|
4
|
+
MonthLowerLimit = 1
|
5
|
+
MonthUpperLimit = 12
|
6
|
+
|
7
|
+
Months = %w{ jan feb mar apr may jun jul aug sep oct nov dec }
|
8
|
+
|
9
|
+
MonthExpression = Months.join('|')
|
10
|
+
|
11
|
+
MonthSingleValuePattern = /\A(#{MonthExpression}|\d+)\z/
|
12
|
+
|
13
|
+
MonthRangePattern = /\A(#{MonthExpression}|\d+)-(#{MonthExpression}|\d+)\z/
|
14
|
+
|
15
|
+
NamedMonthPattern = /\A(#{MonthExpression})\z/
|
16
|
+
|
17
|
+
def initialize
|
18
|
+
super
|
19
|
+
@lower_limit = MonthLowerLimit
|
20
|
+
@upper_limit = MonthUpperLimit
|
21
|
+
@single_value_pattern = MonthSingleValuePattern
|
22
|
+
@range_pattern = MonthRangePattern
|
23
|
+
end
|
24
|
+
|
25
|
+
private
|
26
|
+
|
27
|
+
def convert_value(value)
|
28
|
+
(value =~ NamedMonthPattern) ? Months.index(value) + 1 : value.to_i
|
29
|
+
end
|
30
|
+
|
31
|
+
end
|
32
|
+
end
|
@@ -0,0 +1,23 @@
|
|
1
|
+
module CronSpec
|
2
|
+
|
3
|
+
class RangeCronValue < CronValueBase
|
4
|
+
|
5
|
+
attr_reader :range_lower, :range_upper
|
6
|
+
|
7
|
+
def initialize(lower_limit, upper_limit, range_lower, range_upper)
|
8
|
+
super(lower_limit, upper_limit)
|
9
|
+
@range_lower = range_lower
|
10
|
+
@range_upper = range_upper
|
11
|
+
|
12
|
+
raise "Invalid lower range value: #{@range_lower}" unless is_value_within_limits?(@range_lower)
|
13
|
+
raise "Invalid upper range value: #{@range_upper}" unless is_value_within_limits?(@range_upper)
|
14
|
+
raise "Lower limit must be less than or equal to the upper limit" if @range_lower > @range_upper
|
15
|
+
end
|
16
|
+
|
17
|
+
def is_effective?(value)
|
18
|
+
@range_lower <= value && value <= @range_upper
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
22
|
+
|
23
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module CronSpec
|
2
|
+
|
3
|
+
class SingleValueCronValue < CronValueBase
|
4
|
+
|
5
|
+
attr_reader :single_value
|
6
|
+
|
7
|
+
def initialize(lower_limit, upper_limit, single_value)
|
8
|
+
super(lower_limit, upper_limit)
|
9
|
+
|
10
|
+
@single_value = single_value
|
11
|
+
|
12
|
+
raise "Value is out of range: #{@single_value}" unless is_value_within_limits?(@single_value)
|
13
|
+
end
|
14
|
+
|
15
|
+
def is_effective?(value)
|
16
|
+
@single_value == value
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,21 @@
|
|
1
|
+
module CronSpec
|
2
|
+
|
3
|
+
class StepCronValue < CronValueBase
|
4
|
+
|
5
|
+
attr_reader :step_value
|
6
|
+
|
7
|
+
def initialize(lower_limit, upper_limit, step_value)
|
8
|
+
super(lower_limit, upper_limit)
|
9
|
+
|
10
|
+
@step_value = step_value
|
11
|
+
|
12
|
+
raise "Invalid step value: #{@step_value}" if step_value == 0 || step_value > upper_limit
|
13
|
+
end
|
14
|
+
|
15
|
+
def is_effective?(value)
|
16
|
+
value % @step_value == 0
|
17
|
+
end
|
18
|
+
|
19
|
+
end
|
20
|
+
|
21
|
+
end
|
@@ -0,0 +1,119 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CronSpec::CronSpecification do
|
4
|
+
|
5
|
+
it "should honor the yearly shortcut value" do
|
6
|
+
cs = CronSpec::CronSpecification.new("@yearly")
|
7
|
+
|
8
|
+
# Verify that we will match if at midnight january 1st
|
9
|
+
jan_1_00_00 = Time.new(2011, 1, 1, 0, 0, 0)
|
10
|
+
cs.is_specification_in_effect?(jan_1_00_00).should be true
|
11
|
+
|
12
|
+
# Verify that nothing else matches
|
13
|
+
jan_1_00_10 = Time.new(2011, 1, 1, 0, 10, 0)
|
14
|
+
cs.is_specification_in_effect?(jan_1_00_10).should be false
|
15
|
+
end
|
16
|
+
|
17
|
+
it "should honor the annually shortcut value" do
|
18
|
+
cs = CronSpec::CronSpecification.new("@annually")
|
19
|
+
|
20
|
+
# Verify that we will match if at midnight january 1st
|
21
|
+
jan_1_00_00 = Time.new(2011, 1, 1, 0, 0, 0)
|
22
|
+
cs.is_specification_in_effect?(jan_1_00_00).should be true
|
23
|
+
|
24
|
+
# Verify that nothing else matches
|
25
|
+
jan_1_00_10 = Time.new(2011, 1, 1, 0, 10, 0)
|
26
|
+
cs.is_specification_in_effect?(jan_1_00_10).should be false
|
27
|
+
end
|
28
|
+
|
29
|
+
it "should honor the monthly shortcut value" do
|
30
|
+
cs = CronSpec::CronSpecification.new("@monthly")
|
31
|
+
|
32
|
+
# Verify that we will match if at midnight january 1st
|
33
|
+
(1..12).each do |month|
|
34
|
+
any_month_at_midnight = Time.new(2011, month, 1, 0, 0, 0)
|
35
|
+
cs.is_specification_in_effect?(any_month_at_midnight).should be true
|
36
|
+
end
|
37
|
+
|
38
|
+
# Verify that nothing else matches
|
39
|
+
jan_1_00_10 = Time.new(2011, 1, 2, 0, 10, 0)
|
40
|
+
cs.is_specification_in_effect?(jan_1_00_10).should be false
|
41
|
+
end
|
42
|
+
|
43
|
+
it "should honor the weekly shortcut value" do
|
44
|
+
cs = CronSpec::CronSpecification.new("@weekly")
|
45
|
+
|
46
|
+
# It should honor every sunday
|
47
|
+
(0..3).each do |week|
|
48
|
+
sunday = Time.new(2011, 1, 2 + (week * 7), 0, 0, 0)
|
49
|
+
cs.is_specification_in_effect?(sunday).should be true
|
50
|
+
end
|
51
|
+
# It should ignore every monday
|
52
|
+
(0..3).each do |week|
|
53
|
+
sunday = Time.new(2011, 1, 3 + (week * 7), 0, 0, 0)
|
54
|
+
cs.is_specification_in_effect?(sunday).should be false
|
55
|
+
end
|
56
|
+
end
|
57
|
+
|
58
|
+
it "should honor the daily shortcut value" do
|
59
|
+
cs = CronSpec::CronSpecification.new("@daily")
|
60
|
+
|
61
|
+
# It should honor every day of the week at midnight
|
62
|
+
(1..20).each do |day|
|
63
|
+
sunday = Time.new(2011, 1, day, 0, 0, 0)
|
64
|
+
cs.is_specification_in_effect?(sunday).should be true
|
65
|
+
end
|
66
|
+
# It should ignore every day of the week at times other than midnight
|
67
|
+
(1..20).each do |day|
|
68
|
+
sunday = Time.new(2011, 1, day, 8, 0, 0)
|
69
|
+
cs.is_specification_in_effect?(sunday).should be false
|
70
|
+
end
|
71
|
+
end
|
72
|
+
|
73
|
+
it "should honor the midnight shortcut value" do
|
74
|
+
cs = CronSpec::CronSpecification.new("@midnight")
|
75
|
+
|
76
|
+
# It should honor every day of the week at midnight
|
77
|
+
(1..20).each do |day|
|
78
|
+
sunday = Time.new(2011, 1, day, 0, 0, 0)
|
79
|
+
cs.is_specification_in_effect?(sunday).should be true
|
80
|
+
end
|
81
|
+
# It should ignore every day of the week at times other than midnight
|
82
|
+
(1..20).each do |day|
|
83
|
+
sunday = Time.new(2011, 1, day, 8, 0, 0)
|
84
|
+
cs.is_specification_in_effect?(sunday).should be false
|
85
|
+
end
|
86
|
+
end
|
87
|
+
|
88
|
+
it "should honor the hourly shortcut value" do
|
89
|
+
cs = CronSpec::CronSpecification.new("@hourly")
|
90
|
+
|
91
|
+
# It should honor every day of the week at midnight
|
92
|
+
(0..23).each do |hour|
|
93
|
+
sunday = Time.new(2011, 1, 1, hour, 0, 0)
|
94
|
+
cs.is_specification_in_effect?(sunday).should be true
|
95
|
+
end
|
96
|
+
# It should ignore every day of the week at times other than midnight
|
97
|
+
(0..23).each do |hour|
|
98
|
+
sunday = Time.new(2011, 1, 1, hour, 10, 0)
|
99
|
+
cs.is_specification_in_effect?(sunday).should be false
|
100
|
+
end
|
101
|
+
end
|
102
|
+
|
103
|
+
it "should honor named days of the week" do
|
104
|
+
cs = CronSpec::CronSpecification.new("* * * * mon,tue,thu-sat")
|
105
|
+
|
106
|
+
# Make sure the correct days are honored
|
107
|
+
[1, 2, 4, 5, 6].each do |dow|
|
108
|
+
# next if dow == 4
|
109
|
+
day = Time.new(2011, 1, 2 + dow, 11, 0, 0)
|
110
|
+
cs.is_specification_in_effect?(day).should be true
|
111
|
+
end
|
112
|
+
|
113
|
+
# Make sure the bad days are ignored.
|
114
|
+
[0, 3].each do |dow|
|
115
|
+
day = Time.new(2011, 1, 2 + dow, 11, 0, 0)
|
116
|
+
cs.is_specification_in_effect?(day).should be false
|
117
|
+
end
|
118
|
+
end
|
119
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CronSpec::RangeCronValue do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@cv = CronSpec::RangeCronValue.new(0, 16, 2, 12)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should indicate effective if value is within range" do
|
10
|
+
(2..12).each { | value | @cv.is_effective?(value).should be true }
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should indicate not effective if value is not within range" do
|
14
|
+
(-1..1).each { | value | @cv.is_effective?(value).should be false }
|
15
|
+
(13..16).each { | value | @cv.is_effective?(value).should be false }
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
@@ -0,0 +1,18 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CronSpec::SingleValueCronValue do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@cv = CronSpec::SingleValueCronValue.new(0, 32, 8)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should indicate effective if the value matches" do
|
10
|
+
@cv.is_effective?(8).should be true
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should indicate not effective if value does not match" do
|
14
|
+
(-1..7).each { | value | @cv.is_effective?(value).should be false }
|
15
|
+
(9..32).each { | value | @cv.is_effective?(value).should be false }
|
16
|
+
end
|
17
|
+
|
18
|
+
end
|
data/spec/spec_helper.rb
ADDED
@@ -0,0 +1,12 @@
|
|
1
|
+
$LOAD_PATH.unshift(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
$LOAD_PATH.unshift(File.dirname(__FILE__))
|
3
|
+
require 'rspec'
|
4
|
+
require 'cron-spec'
|
5
|
+
|
6
|
+
# Requires supporting files with custom matchers and macros, etc,
|
7
|
+
# in ./support/ and its subdirectories.
|
8
|
+
Dir["#{File.dirname(__FILE__)}/support/**/*.rb"].each {|f| require f}
|
9
|
+
|
10
|
+
RSpec.configure do |config|
|
11
|
+
|
12
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CronSpec::StepCronValue do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@cv = CronSpec::StepCronValue.new(0, 32, 2)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should indicate effective if the values match the step" do
|
10
|
+
(0..32).each { | value | next unless (value % 2 == 0); @cv.is_effective?(value).should be true }
|
11
|
+
end
|
12
|
+
|
13
|
+
it "should indicate not effective if the values do not match the step" do
|
14
|
+
(0..32).each { | value | next if (value % 2 == 0); @cv.is_effective?(value).should be false }
|
15
|
+
end
|
16
|
+
|
17
|
+
end
|
@@ -0,0 +1,13 @@
|
|
1
|
+
require 'spec_helper'
|
2
|
+
|
3
|
+
describe CronSpec::WildcardCronValue do
|
4
|
+
|
5
|
+
before(:each) do
|
6
|
+
@cv = CronSpec::WildcardCronValue.new(0, 32)
|
7
|
+
end
|
8
|
+
|
9
|
+
it "should indicate effective for all values within limits" do
|
10
|
+
(0..32).each { | value | @cv.is_effective?(value).should be true }
|
11
|
+
end
|
12
|
+
|
13
|
+
end
|
metadata
ADDED
@@ -0,0 +1,164 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: cron-spec
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
prerelease: false
|
5
|
+
segments:
|
6
|
+
- 0
|
7
|
+
- 1
|
8
|
+
- 0
|
9
|
+
version: 0.1.0
|
10
|
+
platform: ruby
|
11
|
+
authors:
|
12
|
+
- Dave Sieh
|
13
|
+
autorequire:
|
14
|
+
bindir: bin
|
15
|
+
cert_chain: []
|
16
|
+
|
17
|
+
date: 2011-02-27 00:00:00 -07:00
|
18
|
+
default_executable:
|
19
|
+
dependencies:
|
20
|
+
- !ruby/object:Gem::Dependency
|
21
|
+
name: rspec
|
22
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
23
|
+
none: false
|
24
|
+
requirements:
|
25
|
+
- - ~>
|
26
|
+
- !ruby/object:Gem::Version
|
27
|
+
segments:
|
28
|
+
- 2
|
29
|
+
- 1
|
30
|
+
- 0
|
31
|
+
version: 2.1.0
|
32
|
+
type: :development
|
33
|
+
prerelease: false
|
34
|
+
version_requirements: *id001
|
35
|
+
- !ruby/object:Gem::Dependency
|
36
|
+
name: bundler
|
37
|
+
requirement: &id002 !ruby/object:Gem::Requirement
|
38
|
+
none: false
|
39
|
+
requirements:
|
40
|
+
- - ~>
|
41
|
+
- !ruby/object:Gem::Version
|
42
|
+
segments:
|
43
|
+
- 1
|
44
|
+
- 0
|
45
|
+
- 0
|
46
|
+
version: 1.0.0
|
47
|
+
type: :development
|
48
|
+
prerelease: false
|
49
|
+
version_requirements: *id002
|
50
|
+
- !ruby/object:Gem::Dependency
|
51
|
+
name: jeweler
|
52
|
+
requirement: &id003 !ruby/object:Gem::Requirement
|
53
|
+
none: false
|
54
|
+
requirements:
|
55
|
+
- - ~>
|
56
|
+
- !ruby/object:Gem::Version
|
57
|
+
segments:
|
58
|
+
- 1
|
59
|
+
- 5
|
60
|
+
- 2
|
61
|
+
version: 1.5.2
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: *id003
|
65
|
+
- !ruby/object:Gem::Dependency
|
66
|
+
name: rcov
|
67
|
+
requirement: &id004 !ruby/object:Gem::Requirement
|
68
|
+
none: false
|
69
|
+
requirements:
|
70
|
+
- - ">="
|
71
|
+
- !ruby/object:Gem::Version
|
72
|
+
segments:
|
73
|
+
- 0
|
74
|
+
version: "0"
|
75
|
+
type: :development
|
76
|
+
prerelease: false
|
77
|
+
version_requirements: *id004
|
78
|
+
description: Cron specification implementation
|
79
|
+
email: dave.sieh@nursinghomequality.com
|
80
|
+
executables: []
|
81
|
+
|
82
|
+
extensions: []
|
83
|
+
|
84
|
+
extra_rdoc_files:
|
85
|
+
- LICENSE.txt
|
86
|
+
- README.rdoc
|
87
|
+
files:
|
88
|
+
- .document
|
89
|
+
- .idea/.name
|
90
|
+
- .idea/.rakeTasks
|
91
|
+
- .idea/cron-spec.iml
|
92
|
+
- .idea/encodings.xml
|
93
|
+
- .idea/misc.xml
|
94
|
+
- .idea/modules.xml
|
95
|
+
- .idea/vcs.xml
|
96
|
+
- .idea/workspace.xml
|
97
|
+
- .rspec
|
98
|
+
- .rvmrc
|
99
|
+
- Gemfile
|
100
|
+
- Gemfile.lock
|
101
|
+
- LICENSE.txt
|
102
|
+
- README.rdoc
|
103
|
+
- Rakefile
|
104
|
+
- VERSION
|
105
|
+
- cron-spec.gemspec
|
106
|
+
- lib/cron-spec.rb
|
107
|
+
- lib/cron-spec/cron_specification.rb
|
108
|
+
- lib/cron-spec/cron_specification_factory.rb
|
109
|
+
- lib/cron-spec/cron_value_base.rb
|
110
|
+
- lib/cron-spec/day_factory.rb
|
111
|
+
- lib/cron-spec/dow_factory.rb
|
112
|
+
- lib/cron-spec/hour_factory.rb
|
113
|
+
- lib/cron-spec/minute_factory.rb
|
114
|
+
- lib/cron-spec/month_factory.rb
|
115
|
+
- lib/cron-spec/range_cron_value.rb
|
116
|
+
- lib/cron-spec/single_value_cron_value.rb
|
117
|
+
- lib/cron-spec/step_cron_value.rb
|
118
|
+
- lib/cron-spec/wildcard_cron_value.rb
|
119
|
+
- spec/cron_specification_spec.rb
|
120
|
+
- spec/range_cron_value_spec.rb
|
121
|
+
- spec/single_value_cron_value_spec.rb
|
122
|
+
- spec/spec_helper.rb
|
123
|
+
- spec/step_cron_value_spec.rb
|
124
|
+
- spec/wildcard_cron_value_spec.rb
|
125
|
+
has_rdoc: true
|
126
|
+
homepage: http://github.com/j0hnds/cron-spec
|
127
|
+
licenses:
|
128
|
+
- MIT
|
129
|
+
post_install_message:
|
130
|
+
rdoc_options: []
|
131
|
+
|
132
|
+
require_paths:
|
133
|
+
- lib
|
134
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
135
|
+
none: false
|
136
|
+
requirements:
|
137
|
+
- - ">="
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
hash: 3189745320292493514
|
140
|
+
segments:
|
141
|
+
- 0
|
142
|
+
version: "0"
|
143
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
144
|
+
none: false
|
145
|
+
requirements:
|
146
|
+
- - ">="
|
147
|
+
- !ruby/object:Gem::Version
|
148
|
+
segments:
|
149
|
+
- 0
|
150
|
+
version: "0"
|
151
|
+
requirements: []
|
152
|
+
|
153
|
+
rubyforge_project:
|
154
|
+
rubygems_version: 1.3.7
|
155
|
+
signing_key:
|
156
|
+
specification_version: 3
|
157
|
+
summary: Cron specification implementation
|
158
|
+
test_files:
|
159
|
+
- spec/cron_specification_spec.rb
|
160
|
+
- spec/range_cron_value_spec.rb
|
161
|
+
- spec/single_value_cron_value_spec.rb
|
162
|
+
- spec/spec_helper.rb
|
163
|
+
- spec/step_cron_value_spec.rb
|
164
|
+
- spec/wildcard_cron_value_spec.rb
|