Class: TowerdataEmail::Validators::TowerdataEmailValidations

Inherits:
ActiveModel::EachValidator
  • Object
show all
Includes:
CommonMethods
Defined in:
lib/towerdata_email/validators.rb

Instance Method Summary collapse

Methods included from CommonMethods

#custom_error_message

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/towerdata_email/validators.rb', line 36

def validate_each(record, attribute, value)
  return true if handle_nil?(record, attribute, value) || handle_blank?(record, attribute, value)

  if eligible_for_validation?(record, attribute)
    e = TowerdataEmail.validate_email(value)
    if e.incorrect?
      if e.corrections && auto_accept_corrections?
        record.send(:"#{attribute}=",  e.corrections.first)
      else
        record.errors[attribute] << custom_error_message(default_failure_message(e), e)
      end
    end
  end
end