Class: SchemaValidations::TimeInDbRangeValidator

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



124
125
126
127
128
129
130
131
132
133
134
135
136
# File 'lib/generated_schema_validations/template.rb', line 124

def validate_each(record, attr_name, value)
  return if value.nil?

  unless value.is_a?(Time) || value.is_a?(ActiveSupport::TimeWithZone)
    record.errors.add(attr_name, :invalid)
    return
  end

  # PostgreSQL allows only times in one day
  return if value.to_date == Date.new(2000, 1, 1)

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