ice_cube 0.10.0 → 0.10.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -21,6 +21,11 @@ module IceCube
21
21
  #
22
22
  class Occurrence < SimpleDelegator
23
23
 
24
+ # Report class name as 'Time' to thwart type checking.
25
+ def self.name
26
+ 'Time'
27
+ end
28
+
24
29
  # Optimize for common methods to avoid method_missing
25
30
  extend Forwardable
26
31
  def_delegators :start_time, :to_s, :to_i, :<=>, :==
@@ -5,6 +5,7 @@ module IceCube
5
5
  include Validations::DailyInterval
6
6
 
7
7
  def initialize(interval = 1)
8
+ super
8
9
  interval(interval)
9
10
  schedule_lock(:hour, :min, :sec)
10
11
  reset
@@ -5,6 +5,7 @@ module IceCube
5
5
  include Validations::HourlyInterval
6
6
 
7
7
  def initialize(interval = 1)
8
+ super
8
9
  interval(interval)
9
10
  schedule_lock(:min, :sec)
10
11
  reset
@@ -5,6 +5,7 @@ module IceCube
5
5
  include Validations::MinutelyInterval
6
6
 
7
7
  def initialize(interval = 1)
8
+ super
8
9
  interval(interval)
9
10
  schedule_lock(:sec)
10
11
  reset
@@ -5,6 +5,7 @@ module IceCube
5
5
  include Validations::MonthlyInterval
6
6
 
7
7
  def initialize(interval = 1)
8
+ super
8
9
  interval(interval)
9
10
  schedule_lock(:day, :hour, :min, :sec)
10
11
  reset
@@ -5,6 +5,7 @@ module IceCube
5
5
  include Validations::SecondlyInterval
6
6
 
7
7
  def initialize(interval = 1)
8
+ super
8
9
  interval(interval)
9
10
  reset
10
11
  end
@@ -5,6 +5,7 @@ module IceCube
5
5
  include Validations::WeeklyInterval
6
6
 
7
7
  def initialize(interval = 1, week_start = :sunday)
8
+ super
8
9
  interval(interval, week_start)
9
10
  schedule_lock(:wday, :hour, :min, :sec)
10
11
  reset
@@ -5,6 +5,7 @@ module IceCube
5
5
  include Validations::YearlyInterval
6
6
 
7
7
  def initialize(interval = 1)
8
+ super
8
9
  interval(interval)
9
10
  schedule_lock(:month, :day, :hour, :min, :sec)
10
11
  reset
@@ -150,7 +150,7 @@ module IceCube
150
150
 
151
151
  # All of the occurrences
152
152
  def all_occurrences
153
- raise ArgumentError.new('Rule must specify either an until date or a count to use #all_occurrences') unless terminating?
153
+ require_terminating_rules
154
154
  find_occurrences(start_time)
155
155
  end
156
156
 
@@ -174,6 +174,7 @@ module IceCube
174
174
 
175
175
  # The remaining occurrences (same requirements as all_occurrences)
176
176
  def remaining_occurrences(from = nil)
177
+ require_terminating_rules
177
178
  from ||= TimeUtil.now(@start_time)
178
179
  find_occurrences(from)
179
180
  end
@@ -426,6 +427,12 @@ module IceCube
426
427
  end
427
428
  end
428
429
 
430
+ def require_terminating_rules
431
+ return true if terminating?
432
+ method_name = caller[0].split(' ').last
433
+ raise ArgumentError, "All recurrence rules must specify .until or .count to use #{method_name}"
434
+ end
435
+
429
436
  def implicit_start_occurrence
430
437
  SingleOccurrenceRule.new(start_time)
431
438
  end
@@ -22,6 +22,7 @@ module IceCube
22
22
  end
23
23
 
24
24
  def self.match_zone(time, reference)
25
+ return unless time = ensure_time(time)
25
26
  if reference.respond_to? :time_zone
26
27
  time.in_time_zone(reference.time_zone)
27
28
  else
@@ -160,7 +161,7 @@ module IceCube
160
161
  # overflowing shorter months
161
162
  def self.days_to_next_month(time)
162
163
  date = Date.new(time.year, time.month, time.day)
163
- (date >> 1) - date
164
+ ((date >> 1) - date).to_i
164
165
  end
165
166
 
166
167
  # Get a day of the month in the month of a given time without overflowing
@@ -30,6 +30,10 @@ module IceCube
30
30
  :interval
31
31
  ]
32
32
 
33
+ def initialize(interval = 1, *)
34
+ @validations = Hash.new
35
+ end
36
+
33
37
  # Compute the next time after (or including) the specified time in respect
34
38
  # to the given schedule
35
39
  def next_time(time, schedule, closing_time)
@@ -74,7 +78,6 @@ module IceCube
74
78
 
75
79
  # Get the collection that contains validations of a certain type
76
80
  def validations_for(key)
77
- @validations ||= {}
78
81
  @validations[key] ||= []
79
82
  end
80
83
 
@@ -8,8 +8,11 @@ module IceCube
8
8
  end
9
9
 
10
10
  def count(max)
11
+ unless max.nil? || max.is_a?(Fixnum)
12
+ raise ArgumentError, "Expecting Fixnum or nil value for count, got #{max.inspect}"
13
+ end
11
14
  @count = max
12
- replace_validations_for(:count, [Validation.new(max, self)]) # replace
15
+ replace_validations_for(:count, [Validation.new(max, self)])
13
16
  self
14
17
  end
15
18
 
@@ -5,7 +5,7 @@ module IceCube
5
5
  # Add a new interval validation
6
6
  def interval(interval)
7
7
  @interval = interval
8
- validations_for(:interval) << Validation.new(interval)
8
+ replace_validations_for(:interval, [Validation.new(interval)])
9
9
  clobber_base_validations(:wday, :day)
10
10
  self
11
11
  end
@@ -5,7 +5,10 @@ module IceCube
5
5
  module Validations::Day
6
6
 
7
7
  def day(*days)
8
- days.each do |day|
8
+ days.flatten.each do |day|
9
+ unless day.is_a?(Fixnum) || day.is_a?(Symbol)
10
+ raise ArgumentError, "expecting Fixnum or Symbol value for day, got #{day.inspect}"
11
+ end
9
12
  day = TimeUtil.sym_to_wday(day)
10
13
  validations_for(:day) << Validation.new(day)
11
14
  end
@@ -5,7 +5,10 @@ module IceCube
5
5
  include Validations::Lock
6
6
 
7
7
  def day_of_month(*days)
8
- days.each do |day|
8
+ days.flatten.each do |day|
9
+ unless day.is_a?(Fixnum)
10
+ raise ArgumentError, "expecting Fixnum value for day, got #{day.inspect}"
11
+ end
9
12
  validations_for(:day_of_month) << Validation.new(day)
10
13
  end
11
14
  clobber_base_validations(:day, :wday)
@@ -3,7 +3,10 @@ module IceCube
3
3
  module Validations::DayOfYear
4
4
 
5
5
  def day_of_year(*days)
6
- days.each do |day|
6
+ days.flatten.each do |day|
7
+ unless day.is_a?(Fixnum)
8
+ raise ArgumentError, "expecting Fixnum value for day, got #{day.inspect}"
9
+ end
7
10
  validations_for(:day_of_year) << Validation.new(day)
8
11
  end
9
12
  clobber_base_validations(:month, :day, :wday)
@@ -6,7 +6,10 @@ module IceCube
6
6
 
7
7
  # Add hour of day validations
8
8
  def hour_of_day(*hours)
9
- hours.each do |hour|
9
+ hours.flatten.each do |hour|
10
+ unless hour.is_a?(Fixnum)
11
+ raise ArgumentError, "expecting Fixnum value for hour, got #{hour.inspect}"
12
+ end
10
13
  validations_for(:hour_of_day) << Validation.new(hour)
11
14
  end
12
15
  clobber_base_validations(:hour)
@@ -4,7 +4,7 @@ module IceCube
4
4
 
5
5
  def interval(interval)
6
6
  @interval = interval
7
- validations_for(:interval) << Validation.new(interval)
7
+ replace_validations_for(:interval, [Validation.new(interval)])
8
8
  clobber_base_validations(:hour)
9
9
  self
10
10
  end
@@ -62,8 +62,8 @@ module IceCube
62
62
  if value && value > 0
63
63
  until_next_month = days_in_month + sleeps
64
64
  else
65
- until_next_month = TimeUtil.days_to_next_month(date) + sleeps
66
- until_next_month -= month_overflow
65
+ until_next_month = start < 28 ? days_in_month : TimeUtil.days_to_next_month(date)
66
+ until_next_month += sleeps - month_overflow
67
67
  end
68
68
 
69
69
  sleeps >= 0 ? sleeps : until_next_month
@@ -5,7 +5,10 @@ module IceCube
5
5
  include Validations::Lock
6
6
 
7
7
  def minute_of_hour(*minutes)
8
- minutes.each do |minute|
8
+ minutes.flatten.each do |minute|
9
+ unless minute.is_a?(Fixnum)
10
+ raise ArgumentError, "expecting Fixnum value for minute, got #{minute.inspect}"
11
+ end
9
12
  validations_for(:minute_of_hour) << Validation.new(minute)
10
13
  end
11
14
  clobber_base_validations(:min)
@@ -4,7 +4,7 @@ module IceCube
4
4
 
5
5
  def interval(interval)
6
6
  @interval = interval
7
- validations_for(:interval) << Validation.new(interval)
7
+ replace_validations_for(:interval, [Validation.new(interval)])
8
8
  clobber_base_validations(:min)
9
9
  self
10
10
  end
@@ -3,7 +3,10 @@ module IceCube
3
3
  module Validations::MonthOfYear
4
4
 
5
5
  def month_of_year(*months)
6
- months.each do |month|
6
+ months.flatten.each do |month|
7
+ unless month.is_a?(Fixnum) || month.is_a?(Symbol)
8
+ raise ArgumentError, "expecting Fixnum or Symbol value for month, got #{month.inspect}"
9
+ end
7
10
  month = TimeUtil.sym_to_month(month)
8
11
  validations_for(:month_of_year) << Validation.new(month)
9
12
  end
@@ -2,9 +2,9 @@ module IceCube
2
2
 
3
3
  module Validations::MonthlyInterval
4
4
 
5
- def interval(interval = 1)
5
+ def interval(interval)
6
6
  @interval = interval
7
- validations_for(:interval) << Validation.new(interval)
7
+ replace_validations_for(:interval, [Validation.new(interval)])
8
8
  clobber_base_validations(:month)
9
9
  self
10
10
  end
@@ -3,7 +3,10 @@ module IceCube
3
3
  module Validations::SecondOfMinute
4
4
 
5
5
  def second_of_minute(*seconds)
6
- seconds.each do |second|
6
+ seconds.flatten.each do |second|
7
+ unless second.is_a?(Fixnum)
8
+ raise ArgumentError, "Expecting Fixnum value for second, got #{second.inspect}"
9
+ end
7
10
  validations_for(:second_of_minute) << Validation.new(second)
8
11
  end
9
12
  clobber_base_validations :sec
@@ -4,7 +4,7 @@ module IceCube
4
4
 
5
5
  def interval(interval)
6
6
  @interval = interval
7
- validations_for(:interval) << Validation.new(interval)
7
+ replace_validations_for(:interval, [Validation.new(interval)])
8
8
  clobber_base_validations(:sec)
9
9
  self
10
10
  end
@@ -11,7 +11,7 @@ module IceCube
11
11
  deprecated_alias :until_date, :until_time
12
12
 
13
13
  def until(time)
14
- time = TimeUtil.ensure_time time, true
14
+ time = TimeUtil.ensure_time(time, true)
15
15
  @until = time
16
16
  replace_validations_for(:until, time.nil? ? nil : [Validation.new(time)])
17
17
  self
@@ -7,7 +7,7 @@ module IceCube
7
7
  def interval(interval, week_start = :sunday)
8
8
  @interval = interval
9
9
  @week_start = TimeUtil.wday_to_sym(week_start)
10
- validations_for(:interval) << Validation.new(interval, week_start)
10
+ replace_validations_for(:interval, [Validation.new(interval, week_start)])
11
11
  clobber_base_validations(:day)
12
12
  self
13
13
  end
@@ -2,9 +2,9 @@ module IceCube
2
2
 
3
3
  module Validations::YearlyInterval
4
4
 
5
- def interval(interval = 1)
5
+ def interval(interval)
6
6
  @interval = interval
7
- validations_for(:interval) << Validation.new(interval)
7
+ replace_validations_for(:interval, [Validation.new(interval)])
8
8
  clobber_base_validations(:year)
9
9
  end
10
10
 
@@ -1,5 +1,5 @@
1
1
  module IceCube
2
2
 
3
- VERSION = '0.10.0'
3
+ VERSION = '0.10.1'
4
4
 
5
5
  end
metadata CHANGED
@@ -1,69 +1,78 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ice_cube
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.10.0
4
+ version: 0.10.1
5
+ prerelease:
5
6
  platform: ruby
6
7
  authors:
7
8
  - John Crepezzi
8
9
  autorequire:
9
10
  bindir: bin
10
11
  cert_chain: []
11
- date: 2013-02-25 00:00:00.000000000 Z
12
+ date: 2013-05-17 00:00:00.000000000 Z
12
13
  dependencies:
13
14
  - !ruby/object:Gem::Dependency
14
15
  name: rake
15
16
  requirement: !ruby/object:Gem::Requirement
17
+ none: false
16
18
  requirements:
17
- - - '>='
19
+ - - ! '>='
18
20
  - !ruby/object:Gem::Version
19
21
  version: '0'
20
22
  type: :development
21
23
  prerelease: false
22
24
  version_requirements: !ruby/object:Gem::Requirement
25
+ none: false
23
26
  requirements:
24
- - - '>='
27
+ - - ! '>='
25
28
  - !ruby/object:Gem::Version
26
29
  version: '0'
27
30
  - !ruby/object:Gem::Dependency
28
31
  name: rspec
29
32
  requirement: !ruby/object:Gem::Requirement
33
+ none: false
30
34
  requirements:
31
- - - '>='
35
+ - - ! '>='
32
36
  - !ruby/object:Gem::Version
33
37
  version: '0'
34
38
  type: :development
35
39
  prerelease: false
36
40
  version_requirements: !ruby/object:Gem::Requirement
41
+ none: false
37
42
  requirements:
38
- - - '>='
43
+ - - ! '>='
39
44
  - !ruby/object:Gem::Version
40
45
  version: '0'
41
46
  - !ruby/object:Gem::Dependency
42
47
  name: active_support
43
48
  requirement: !ruby/object:Gem::Requirement
49
+ none: false
44
50
  requirements:
45
- - - '>='
51
+ - - ! '>='
46
52
  - !ruby/object:Gem::Version
47
53
  version: 3.0.0
48
54
  type: :development
49
55
  prerelease: false
50
56
  version_requirements: !ruby/object:Gem::Requirement
57
+ none: false
51
58
  requirements:
52
- - - '>='
59
+ - - ! '>='
53
60
  - !ruby/object:Gem::Version
54
61
  version: 3.0.0
55
62
  - !ruby/object:Gem::Dependency
56
63
  name: tzinfo
57
64
  requirement: !ruby/object:Gem::Requirement
65
+ none: false
58
66
  requirements:
59
- - - '>='
67
+ - - ! '>='
60
68
  - !ruby/object:Gem::Version
61
69
  version: '0'
62
70
  type: :development
63
71
  prerelease: false
64
72
  version_requirements: !ruby/object:Gem::Requirement
73
+ none: false
65
74
  requirements:
66
- - - '>='
75
+ - - ! '>='
67
76
  - !ruby/object:Gem::Version
68
77
  version: '0'
69
78
  description: ice_cube is a recurring date library for Ruby. It allows for quick,
@@ -119,26 +128,33 @@ files:
119
128
  homepage: http://seejohnrun.github.com/ice_cube/
120
129
  licenses:
121
130
  - MIT
122
- metadata: {}
123
131
  post_install_message:
124
132
  rdoc_options: []
125
133
  require_paths:
126
134
  - lib
127
135
  required_ruby_version: !ruby/object:Gem::Requirement
136
+ none: false
128
137
  requirements:
129
- - - '>='
138
+ - - ! '>='
130
139
  - !ruby/object:Gem::Version
131
140
  version: '0'
141
+ segments:
142
+ - 0
143
+ hash: 2800901123420442900
132
144
  required_rubygems_version: !ruby/object:Gem::Requirement
145
+ none: false
133
146
  requirements:
134
- - - '>='
147
+ - - ! '>='
135
148
  - !ruby/object:Gem::Version
136
149
  version: '0'
150
+ segments:
151
+ - 0
152
+ hash: 2800901123420442900
137
153
  requirements: []
138
154
  rubyforge_project: ice-cube
139
- rubygems_version: 2.0.0
155
+ rubygems_version: 1.8.25
140
156
  signing_key:
141
- specification_version: 4
157
+ specification_version: 3
142
158
  summary: Ruby Date Recurrence Library
143
159
  test_files:
144
160
  - spec/spec_helper.rb
checksums.yaml DELETED
@@ -1,7 +0,0 @@
1
- ---
2
- SHA1:
3
- metadata.gz: 0cc5c669bd801317d8256d7fc8b77841e80dae6e
4
- data.tar.gz: 6bda80589b1d0a91d54ea2d7b4194d320e26b2ac
5
- SHA512:
6
- metadata.gz: d3a10207a9dc7368b3cc6f045160c2b3f6651e1a95570a8d6c58af689eb616deb47291485b514b4ec58b1275595dce7f7c21f1606341d624449edfc5c842648d
7
- data.tar.gz: 0abec738ddd565630a8a92468a8db708c2c18e2601abe3824ba10b766ce952341d7ff90da50a7ac6f4349d079661d66e8b131f177cbf4ee2853b4b046d4389a6