Class: SchemaValidations::DateTimeInDbRangeValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/generated_schema_validations/template.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attr_name, value) ⇒ Object



102
103
104
105
106
107
108
# File 'lib/generated_schema_validations/template.rb', line 102

def validate_each(record, attr_name, value)
  return if value.nil?
  return unless value.is_a?(DateTime) || value.is_a?(Time)
  return if value.year.between?(-4711, 294275) # see https://www.postgresql.org/docs/9.3/datatype-datetime.html

  record.errors.add(attr_name, :invalid, options)
end