ice_cube 0.7.6 → 0.7.7
Sign up to get free protection for your applications and to get access to all the features.
- data/lib/ice_cube/deprecated.rb +28 -0
- data/lib/ice_cube/rule.rb +2 -2
- data/lib/ice_cube/schedule.rb +26 -17
- data/lib/ice_cube/validations/day.rb +13 -3
- data/lib/ice_cube/validations/until.rb +3 -1
- data/lib/ice_cube/version.rb +1 -1
- data/lib/ice_cube.rb +5 -0
- data/spec/spec_helper.rb +5 -7
- metadata +38 -37
@@ -0,0 +1,28 @@
|
|
1
|
+
module Deprecated
|
2
|
+
|
3
|
+
# Define a deprecated alias for a method
|
4
|
+
# @param [Symbol] name - name of method to define
|
5
|
+
# @param [Symbol] replacement - name of method to replace (alias)
|
6
|
+
def deprecated_alias(name, replacement)
|
7
|
+
# Create a wrapped version
|
8
|
+
define_method(name) do |*args, &block|
|
9
|
+
warn "IceCube: ##{name} deprecated (please use ##{replacement})"
|
10
|
+
send replacement, *args, &block
|
11
|
+
end
|
12
|
+
end
|
13
|
+
|
14
|
+
# Deprecate a defined method
|
15
|
+
# @param [Symbol] name - name of deprecated method
|
16
|
+
# @param [Symbol] replacement - name of the desired replacement
|
17
|
+
def deprecated(name, replacement)
|
18
|
+
# Replace old method
|
19
|
+
old_name = :"#{name}_without_deprecation"
|
20
|
+
alias_method old_name, name
|
21
|
+
# And replace it with a wrapped version
|
22
|
+
define_method(name) do |*args, &block|
|
23
|
+
warn "IceCube: ##{name} deprecated (please use ##{replacement})"
|
24
|
+
send old_name, *args, &block
|
25
|
+
end
|
26
|
+
end
|
27
|
+
|
28
|
+
end
|
data/lib/ice_cube/rule.rb
CHANGED
@@ -30,12 +30,12 @@ module IceCube
|
|
30
30
|
|
31
31
|
# Yaml implementation
|
32
32
|
def to_yaml(*args)
|
33
|
-
|
33
|
+
IceCube::use_psych? ? Psych::dump(to_hash) : YAML::dump(to_hash, *args)
|
34
34
|
end
|
35
35
|
|
36
36
|
# From yaml
|
37
37
|
def self.from_yaml(yaml)
|
38
|
-
from_hash
|
38
|
+
from_hash IceCube::use_psych? ? Psych::load(yaml) : YAML::load(yaml)
|
39
39
|
end
|
40
40
|
|
41
41
|
# Expected to be overridden by subclasses
|
data/lib/ice_cube/schedule.rb
CHANGED
@@ -4,17 +4,20 @@ module IceCube
|
|
4
4
|
|
5
5
|
class Schedule
|
6
6
|
|
7
|
+
extend ::Deprecated
|
8
|
+
|
7
9
|
# Get the start time
|
8
10
|
attr_accessor :start_time
|
9
|
-
|
10
|
-
|
11
|
+
deprecated_alias :start_date, :start_time
|
12
|
+
deprecated_alias :start_date=, :start_time=
|
11
13
|
|
12
14
|
# Get the duration
|
13
15
|
attr_accessor :duration
|
14
16
|
|
15
17
|
# Get the end time
|
16
18
|
attr_accessor :end_time
|
17
|
-
|
19
|
+
deprecated_alias :end_date, :end_time
|
20
|
+
deprecated_alias :end_date=, :end_time=
|
18
21
|
|
19
22
|
# Create a new schedule
|
20
23
|
def initialize(start_time = nil, options = {})
|
@@ -32,8 +35,9 @@ module IceCube
|
|
32
35
|
add_recurrence_rule rule
|
33
36
|
time
|
34
37
|
end
|
35
|
-
alias :
|
36
|
-
|
38
|
+
alias :rtime :add_recurrence_time
|
39
|
+
deprecated_alias :rdate, :rtime
|
40
|
+
deprecated_alias :add_recurrence_date, :add_recurrence_time
|
37
41
|
|
38
42
|
# Add an exception time to the schedule
|
39
43
|
def add_exception_time(time)
|
@@ -42,8 +46,9 @@ module IceCube
|
|
42
46
|
add_exception_rule rule
|
43
47
|
time
|
44
48
|
end
|
45
|
-
alias :
|
46
|
-
|
49
|
+
alias :extime :add_exception_time
|
50
|
+
deprecated_alias :exdate, :extime
|
51
|
+
deprecated_alias :add_exception_date, :add_exception_time
|
47
52
|
|
48
53
|
# Add a recurrence rule to the schedule
|
49
54
|
def add_recurrence_rule(rule)
|
@@ -85,8 +90,9 @@ module IceCube
|
|
85
90
|
def recurrence_times
|
86
91
|
@all_recurrence_rules.select { |r| r.is_a?(SingleOccurrenceRule) }.map(&:time)
|
87
92
|
end
|
88
|
-
alias :
|
89
|
-
|
93
|
+
alias :rtimes :recurrence_times
|
94
|
+
deprecated_alias :rdates, :rtimes
|
95
|
+
deprecated_alias :recurrence_dates, :recurrence_times
|
90
96
|
|
91
97
|
# Remove a recurrence time
|
92
98
|
def remove_recurrence_time(time)
|
@@ -96,15 +102,17 @@ module IceCube
|
|
96
102
|
end
|
97
103
|
time if found
|
98
104
|
end
|
99
|
-
alias :
|
100
|
-
|
105
|
+
alias :remove_rtime :remove_recurrence_time
|
106
|
+
deprecated_alias :remove_recurrence_date, :remove_recurrence_time
|
107
|
+
deprecated_alias :remove_rdate, :remove_rtime
|
101
108
|
|
102
109
|
# Get the exception times that are on the schedule
|
103
110
|
def exception_times
|
104
111
|
@all_exception_rules.select { |r| r.is_a?(SingleOccurrenceRule) }.map(&:time)
|
105
112
|
end
|
106
|
-
alias :
|
107
|
-
|
113
|
+
alias :extimes :exception_times
|
114
|
+
deprecated_alias :exdates, :extimes
|
115
|
+
deprecated_alias :exception_dates, :exception_times
|
108
116
|
|
109
117
|
# Remove an exception time
|
110
118
|
def remove_exception_time(time)
|
@@ -114,8 +122,9 @@ module IceCube
|
|
114
122
|
end
|
115
123
|
time if found
|
116
124
|
end
|
117
|
-
alias :
|
118
|
-
|
125
|
+
alias :remove_extime :remove_exception_time
|
126
|
+
deprecated_alias :remove_exception_date, :remove_exception_time
|
127
|
+
deprecated_alias :remove_exdate, :remove_extime
|
119
128
|
|
120
129
|
# Get all of the occurrences from the start_time up until a
|
121
130
|
# given Time
|
@@ -253,12 +262,12 @@ module IceCube
|
|
253
262
|
|
254
263
|
# Convert the schedule to yaml
|
255
264
|
def to_yaml(*args)
|
256
|
-
|
265
|
+
IceCube::use_psych? ? Psych::dump(to_hash, *args) : YAML::dump(to_hash, *args)
|
257
266
|
end
|
258
267
|
|
259
268
|
# Load the schedule from yaml
|
260
269
|
def self.from_yaml(yaml, options = {})
|
261
|
-
from_hash
|
270
|
+
from_hash IceCube::use_psych? ? Psych::load(yaml) : YAML::load(yaml), options
|
262
271
|
end
|
263
272
|
|
264
273
|
# Convert the schedule to a hash
|
@@ -25,7 +25,7 @@ module IceCube
|
|
25
25
|
end
|
26
26
|
|
27
27
|
def build_s(builder)
|
28
|
-
builder.piece(:day) <<
|
28
|
+
builder.piece(:day) << day
|
29
29
|
end
|
30
30
|
|
31
31
|
def build_hash(builder)
|
@@ -44,8 +44,18 @@ module IceCube
|
|
44
44
|
:wday
|
45
45
|
end
|
46
46
|
|
47
|
-
StringBuilder.register_formatter(:day) do |
|
48
|
-
|
47
|
+
StringBuilder.register_formatter(:day) do |validation_days|
|
48
|
+
# sort the days
|
49
|
+
validation_days.sort!
|
50
|
+
# pick the right shortening, if applicable
|
51
|
+
if validation_days == [0, 6]
|
52
|
+
'on Weekends'
|
53
|
+
elsif validation_days == (1..5).to_a
|
54
|
+
'on Weekdays'
|
55
|
+
else
|
56
|
+
segments = validation_days.map { |d| "#{Date::DAYNAMES[d]}s" }
|
57
|
+
"on #{StringBuilder.sentence(segments)}"
|
58
|
+
end
|
49
59
|
end
|
50
60
|
|
51
61
|
end
|
data/lib/ice_cube/version.rb
CHANGED
data/lib/ice_cube.rb
CHANGED
@@ -1,4 +1,5 @@
|
|
1
1
|
require 'date'
|
2
|
+
require 'ice_cube/deprecated'
|
2
3
|
|
3
4
|
# Use psych if we can
|
4
5
|
begin
|
@@ -71,4 +72,8 @@ module IceCube
|
|
71
72
|
# Formatting
|
72
73
|
TO_S_TIME_FORMAT = '%B %e, %Y'
|
73
74
|
|
75
|
+
def self.use_psych?
|
76
|
+
@use_psych ||= defined?(Psych) && Psych::VERSION
|
77
|
+
end
|
78
|
+
|
74
79
|
end
|
data/spec/spec_helper.rb
CHANGED
@@ -1,13 +1,11 @@
|
|
1
|
-
require File.dirname(__FILE__) + '/../lib/ice_cube'
|
2
|
-
|
3
1
|
begin
|
4
|
-
require '
|
5
|
-
|
6
|
-
at_exit do
|
7
|
-
CoverMe.complete!
|
8
|
-
end
|
2
|
+
require 'simplecov'
|
3
|
+
SimpleCov.start
|
9
4
|
rescue LoadError
|
5
|
+
# okay
|
10
6
|
end
|
11
7
|
|
8
|
+
require File.dirname(__FILE__) + '/../lib/ice_cube'
|
9
|
+
|
12
10
|
DAY = Time.utc(2010, 3, 1)
|
13
11
|
WEDNESDAY = Time.utc(2010, 6, 23, 5, 0, 0)
|
metadata
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: ice_cube
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.7.
|
4
|
+
version: 0.7.7
|
5
5
|
prerelease:
|
6
6
|
platform: ruby
|
7
7
|
authors:
|
@@ -9,11 +9,11 @@ authors:
|
|
9
9
|
autorequire:
|
10
10
|
bindir: bin
|
11
11
|
cert_chain: []
|
12
|
-
date: 2012-
|
12
|
+
date: 2012-02-15 00:00:00.000000000Z
|
13
13
|
dependencies:
|
14
14
|
- !ruby/object:Gem::Dependency
|
15
15
|
name: rspec
|
16
|
-
requirement: &
|
16
|
+
requirement: &2153297040 !ruby/object:Gem::Requirement
|
17
17
|
none: false
|
18
18
|
requirements:
|
19
19
|
- - ! '>='
|
@@ -21,10 +21,10 @@ dependencies:
|
|
21
21
|
version: '0'
|
22
22
|
type: :development
|
23
23
|
prerelease: false
|
24
|
-
version_requirements: *
|
24
|
+
version_requirements: *2153297040
|
25
25
|
- !ruby/object:Gem::Dependency
|
26
26
|
name: active_support
|
27
|
-
requirement: &
|
27
|
+
requirement: &2153296340 !ruby/object:Gem::Requirement
|
28
28
|
none: false
|
29
29
|
requirements:
|
30
30
|
- - ! '>='
|
@@ -32,10 +32,10 @@ dependencies:
|
|
32
32
|
version: 3.0.0
|
33
33
|
type: :development
|
34
34
|
prerelease: false
|
35
|
-
version_requirements: *
|
35
|
+
version_requirements: *2153296340
|
36
36
|
- !ruby/object:Gem::Dependency
|
37
37
|
name: tzinfo
|
38
|
-
requirement: &
|
38
|
+
requirement: &2153295880 !ruby/object:Gem::Requirement
|
39
39
|
none: false
|
40
40
|
requirements:
|
41
41
|
- - ! '>='
|
@@ -43,7 +43,7 @@ dependencies:
|
|
43
43
|
version: '0'
|
44
44
|
type: :development
|
45
45
|
prerelease: false
|
46
|
-
version_requirements: *
|
46
|
+
version_requirements: *2153295880
|
47
47
|
description: ice_cube is a recurring date library for Ruby. It allows for quick,
|
48
48
|
programatic expansion of recurring date rules.
|
49
49
|
email: john@crepezzi.com
|
@@ -51,43 +51,44 @@ executables: []
|
|
51
51
|
extensions: []
|
52
52
|
extra_rdoc_files: []
|
53
53
|
files:
|
54
|
-
- lib/ice_cube/
|
54
|
+
- lib/ice_cube/builders/hash_builder.rb
|
55
|
+
- lib/ice_cube/builders/ical_builder.rb
|
56
|
+
- lib/ice_cube/builders/string_builder.rb
|
57
|
+
- lib/ice_cube/deprecated.rb
|
58
|
+
- lib/ice_cube/errors/count_exceeded.rb
|
59
|
+
- lib/ice_cube/errors/until_exceeded.rb
|
60
|
+
- lib/ice_cube/rule.rb
|
61
|
+
- lib/ice_cube/rules/daily_rule.rb
|
62
|
+
- lib/ice_cube/rules/hourly_rule.rb
|
63
|
+
- lib/ice_cube/rules/minutely_rule.rb
|
64
|
+
- lib/ice_cube/rules/monthly_rule.rb
|
65
|
+
- lib/ice_cube/rules/secondly_rule.rb
|
66
|
+
- lib/ice_cube/rules/weekly_rule.rb
|
67
|
+
- lib/ice_cube/rules/yearly_rule.rb
|
55
68
|
- lib/ice_cube/schedule.rb
|
56
|
-
- lib/ice_cube/
|
69
|
+
- lib/ice_cube/single_occurrence_rule.rb
|
57
70
|
- lib/ice_cube/time_util.rb
|
58
|
-
- lib/ice_cube/
|
59
|
-
- lib/ice_cube/validations/
|
71
|
+
- lib/ice_cube/validated_rule.rb
|
72
|
+
- lib/ice_cube/validations/count.rb
|
73
|
+
- lib/ice_cube/validations/daily_interval.rb
|
74
|
+
- lib/ice_cube/validations/day.rb
|
75
|
+
- lib/ice_cube/validations/day_of_month.rb
|
60
76
|
- lib/ice_cube/validations/day_of_week.rb
|
77
|
+
- lib/ice_cube/validations/day_of_year.rb
|
78
|
+
- lib/ice_cube/validations/hour_of_day.rb
|
61
79
|
- lib/ice_cube/validations/hourly_interval.rb
|
62
|
-
- lib/ice_cube/validations/minutely_interval.rb
|
63
80
|
- lib/ice_cube/validations/lock.rb
|
81
|
+
- lib/ice_cube/validations/minute_of_hour.rb
|
82
|
+
- lib/ice_cube/validations/minutely_interval.rb
|
64
83
|
- lib/ice_cube/validations/month_of_year.rb
|
65
|
-
- lib/ice_cube/validations/yearly_interval.rb
|
66
|
-
- lib/ice_cube/validations/schedule_lock.rb
|
67
|
-
- lib/ice_cube/validations/hour_of_day.rb
|
68
|
-
- lib/ice_cube/validations/until.rb
|
69
84
|
- lib/ice_cube/validations/monthly_interval.rb
|
70
|
-
- lib/ice_cube/validations/
|
71
|
-
- lib/ice_cube/validations/day_of_month.rb
|
85
|
+
- lib/ice_cube/validations/schedule_lock.rb
|
72
86
|
- lib/ice_cube/validations/second_of_minute.rb
|
87
|
+
- lib/ice_cube/validations/secondly_interval.rb
|
88
|
+
- lib/ice_cube/validations/until.rb
|
73
89
|
- lib/ice_cube/validations/weekly_interval.rb
|
74
|
-
- lib/ice_cube/validations/
|
75
|
-
- lib/ice_cube/
|
76
|
-
- lib/ice_cube/validations/day.rb
|
77
|
-
- lib/ice_cube/rules/hourly_rule.rb
|
78
|
-
- lib/ice_cube/rules/minutely_rule.rb
|
79
|
-
- lib/ice_cube/rules/yearly_rule.rb
|
80
|
-
- lib/ice_cube/rules/secondly_rule.rb
|
81
|
-
- lib/ice_cube/rules/weekly_rule.rb
|
82
|
-
- lib/ice_cube/rules/daily_rule.rb
|
83
|
-
- lib/ice_cube/rules/monthly_rule.rb
|
84
|
-
- lib/ice_cube/errors/until_exceeded.rb
|
85
|
-
- lib/ice_cube/errors/count_exceeded.rb
|
86
|
-
- lib/ice_cube/rule.rb
|
87
|
-
- lib/ice_cube/validated_rule.rb
|
88
|
-
- lib/ice_cube/builders/ical_builder.rb
|
89
|
-
- lib/ice_cube/builders/string_builder.rb
|
90
|
-
- lib/ice_cube/builders/hash_builder.rb
|
90
|
+
- lib/ice_cube/validations/yearly_interval.rb
|
91
|
+
- lib/ice_cube/version.rb
|
91
92
|
- lib/ice_cube.rb
|
92
93
|
- spec/spec_helper.rb
|
93
94
|
homepage: http://seejohnrun.github.com/ice_cube/
|
@@ -110,7 +111,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
110
111
|
version: '0'
|
111
112
|
requirements: []
|
112
113
|
rubyforge_project: ice-cube
|
113
|
-
rubygems_version: 1.8.
|
114
|
+
rubygems_version: 1.8.15
|
114
115
|
signing_key:
|
115
116
|
specification_version: 3
|
116
117
|
summary: Ruby Date Recurrence Library
|