Class: Sequent::Core::Helpers::DateTimeValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/sequent/core/helpers/date_time_validator.rb

Overview

Validates DateTimes Automatically included when using a

attrs value: DateTime

Instance Method Summary collapse

Instance Method Details

#validate_each(subject, attribute, value) ⇒ Object



13
14
15
16
17
18
19
# File 'lib/sequent/core/helpers/date_time_validator.rb', line 13

def validate_each(subject, attribute, value)
  return if value.is_a?(DateTime)

  DateTime.deserialize_from_json(value)
rescue StandardError
  subject.errors.add attribute, :invalid_date_time
end