Class: EmailVerifier::ValidatesEmailRealness::Validator::EmailRealnessValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
lib/email_verifier/validates_email_realness.rb

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'lib/email_verifier/validates_email_realness.rb', line 8

def validate_each(record, attribute, value)
  begin
    record.errors.add attribute, 'must point to a real mail account' unless EmailVerifier.check(value)
  rescue EmailVerifier::OutOfMailServersException
    record.errors.add attribute, 'appears to point to dead mail server'
  rescue EmailVerifier::NoMailServerException
    record.errors.add attribute, "appears to point to domain which doesn't handle e-mail"
  rescue EmailVerifier::FailureException
    record.errors.add attribute, "could not be checked if is real"
  end
end