Module: IceCube::Validations::Lock

Included in:
Day::Validation, DayOfMonth, DayOfMonth::Validation, HourOfDay, HourOfDay::Validation, MinuteOfHour, MinuteOfHour::Validation, MonthOfYear::Validation, ScheduleLock::Validation, SecondOfMinute::Validation
Defined in:
lib/ice_cube/validations/lock.rb

Overview

A validation mixin that will lock the type field to value or +schedule.start_time.send(type) if value is nil

Constant Summary

INTERVALS =
{:min => 60, :sec => 60, :month => 12, :wday => 7}

Instance Method Summary (collapse)

Instance Method Details

- (Object) validate(time, schedule)



10
11
12
13
14
15
# File 'lib/ice_cube/validations/lock.rb', line 10

def validate(time, schedule)
  return send(:validate_#{type}_lock", time, schedule) unless INTERVALS[type]
  start = value || schedule.start_time.send(type)
  start = INTERVALS[type] + start if start < 0 # handle negative values
  start >= time.send(type) ? start - time.send(type) : INTERVALS[type] - time.send(type) + start
end