class DefraRuby::Validators::PastDateValidator

Public Instance Methods

validate_each(record, attribute, value) click to toggle source
# File lib/defra_ruby/validators/past_date_validator.rb, line 6
def validate_each(record, attribute, value)
  return false if value.blank?

  date = value.to_date

  if date > Date.today
    add_validation_error(record, attribute, :past_date)

    return false
  end

  if date.year < 1900
    add_validation_error(record, attribute, :invalid_date)

    return false
  end

  true
end