class Tuning::Validations::TimeValidator

Constants

CHECKS

Public Instance Methods

validate_each(record, attribute, value) click to toggle source
# File lib/tuning/validations/time.rb, line 8
def validate_each(record, attribute, value)
  if [Date, Time].any? { |klass| value.kind_of?(klass) }
    CHECKS.each do |name, operator|
      if options.has_key?(name)
        other = options[name]
        case other
        when Symbol
          other = record.send(other)
        when Proc
          other = other.call(record)
        end
        unless value.send(operator, other)
          record.errors.add attribute, name, time: I18n.l(other)
        end
      end
    end
  else
    record.errors.add attribute, :not_a_time
  end
end