Module: IceCube::Validations::Lock

Overview

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

Constant Summary collapse

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

Instance Method Summary collapse

Instance Method Details

#validate(time, schedule) ⇒ Object



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

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