Class: DefraRuby::Validators::PastDateValidator

Inherits:
BaseValidator
  • Object
show all
Defined in:
lib/defra_ruby/validators/past_date_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# 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