Class: Hydra::FutureDateValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
app/validators/hydra/future_date_validator.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'app/validators/hydra/future_date_validator.rb', line 4

def validate_each(record, attribute, value)
  if value.present?
    begin
      if date = value.to_date
        if date <= Date.today
          record.errors.add(attribute, "Must be a future date")
        end
      else
        record.errors.add(attribute, "Invalid Date Format")
      end
    rescue ArgumentError, NoMethodError
      record.errors.add(attribute, "Invalid Date Format")
    end
  end
end