Class: IceCube::ValidatedRule
- Includes:
- IceCube::Validations::Count, IceCube::Validations::Day, IceCube::Validations::DayOfMonth, IceCube::Validations::DayOfWeek, IceCube::Validations::DayOfYear, IceCube::Validations::HourOfDay, IceCube::Validations::MinuteOfHour, IceCube::Validations::MonthOfYear, IceCube::Validations::ScheduleLock, IceCube::Validations::SecondOfMinute, IceCube::Validations::Until
- Defined in:
- lib/ice_cube/validated_rule.rb
Direct Known Subclasses
DailyRule, HourlyRule, MinutelyRule, MonthlyRule, SecondlyRule, WeeklyRule, YearlyRule
Constant Summary
Constants included from IceCube::Validations::Lock
IceCube::Validations::Lock::INTERVALS
Instance Attribute Summary
Attributes inherited from Rule
Instance Method Summary collapse
-
#clobber_base_validations(*types) ⇒ Object
Remove the specified base validations.
-
#next_time(time, schedule, closing_time) ⇒ Object
Compute the next time after (or including) the specified time in respect to the given schedule NOTE: optimization target, sort the rules by their type, year first so we can make bigger jumps more often.
-
#replace_validations_for(key, arr) ⇒ Object
Fully replace validations.
- #to_hash ⇒ Object
- #to_ical ⇒ Object
- #to_s ⇒ Object
-
#validations_for(key) ⇒ Object
Get the collection that contains validations of a certain type.
Methods included from IceCube::Validations::Until
Methods included from Deprecated
#deprecated, #deprecated_alias
Methods included from IceCube::Validations::Count
Methods included from IceCube::Validations::DayOfYear
Methods included from IceCube::Validations::MonthOfYear
Methods included from IceCube::Validations::Day
Methods included from IceCube::Validations::DayOfWeek
Methods included from IceCube::Validations::DayOfMonth
Methods included from IceCube::Validations::Lock
Methods included from IceCube::Validations::SecondOfMinute
Methods included from IceCube::Validations::MinuteOfHour
Methods included from IceCube::Validations::HourOfDay
Methods included from IceCube::Validations::ScheduleLock
Methods inherited from Rule
#==, daily, from_hash, from_ical, from_yaml, #full_required?, #hash, hourly, minutely, monthly, #on?, #reset, secondly, #terminating?, #to_yaml, weekly, yearly
Instance Method Details
#clobber_base_validations(*types) ⇒ Object
Remove the specified base validations
100 101 102 103 104 |
# File 'lib/ice_cube/validated_rule.rb', line 100 def clobber_base_validations(*types) types.each do |type| @validations.delete(:"base_#{type}") end end |
#next_time(time, schedule, closing_time) ⇒ Object
Compute the next time after (or including) the specified time in respect to the given schedule NOTE: optimization target, sort the rules by their type, year first so we can make bigger jumps more often
23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 |
# File 'lib/ice_cube/validated_rule.rb', line 23 def next_time(time, schedule, closing_time) loop do break if @validations.all? do |name, vals| # Execute each validation res = vals.map do |validation| validation.validate(time, schedule) end # If there is any nil, then we're set - otherwise choose the lowest if res.any? { |r| r.nil? || r == 0 } true else return nil if res.all? { |r| r === true } # allow quick escaping res.reject! { |r| r.nil? || r == 0 || r === true } if fwd = res.min type = vals.first.type # get the jump type dst_adjust = !vals.first.respond_to?(:dst_adjust?) || vals.first.dst_adjust? wrapper = TimeUtil::TimeWrapper.new(time, dst_adjust) wrapper.add(type, fwd) wrapper.clear_below(type) time = wrapper.to_time end false end end # Prevent a non-matching infinite loop return nil if closing_time && time > closing_time end # NOTE Uses may be 1 higher than proper here since end_time isn't # validated in this class. This is okay now, since we never expose it - # but if we ever do - we should check that above this line, and return # nil if end_time is past @uses += 1 if time time end |
#replace_validations_for(key, arr) ⇒ Object
Fully replace validations
95 96 97 |
# File 'lib/ice_cube/validated_rule.rb', line 95 def replace_validations_for(key, arr) @validations[key] = arr end |
#to_hash ⇒ Object
68 69 70 71 72 73 74 75 76 |
# File 'lib/ice_cube/validated_rule.rb', line 68 def to_hash builder = HashBuilder.new(self) @validations.each do |name, validations| validations.each do |validation| validation.build_hash(builder) end end builder.to_hash end |
#to_ical ⇒ Object
78 79 80 81 82 83 84 85 86 |
# File 'lib/ice_cube/validated_rule.rb', line 78 def to_ical builder = IcalBuilder.new @validations.each do |name, validations| validations.each do |validation| validation.build_ical(builder) end end builder.to_s end |
#to_s ⇒ Object
58 59 60 61 62 63 64 65 66 |
# File 'lib/ice_cube/validated_rule.rb', line 58 def to_s builder = StringBuilder.new @validations.each do |name, validations| validations.each do |validation| validation.build_s(builder) end end builder.to_s end |
#validations_for(key) ⇒ Object
Get the collection that contains validations of a certain type
89 90 91 92 |
# File 'lib/ice_cube/validated_rule.rb', line 89 def validations_for(key) @validations ||= {} @validations[key] ||= [] end |