Class: ATDIS::Validators::PresenceBeforeTypeCastValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/atdis/validators.rb

Overview

Take into account the value before type casting

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, _value) ⇒ Object



78
79
80
81
82
83
84
85
# File 'lib/atdis/validators.rb', line 78

def validate_each(record, attribute, _value)
  raw_value = record.send("#{attribute}_before_type_cast")
  return unless !raw_value.is_a?(Array) && !raw_value.present?

  message = "can't be blank"
  message = ErrorMessage[message, options[:spec_section]] if options[:spec_section]
  record.errors.add(attribute, message)
end