Class: EmailAddressValidator

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

Instance Method Summary collapse

Instance Method Details

#default_optionsObject



7
8
9
# File 'lib/validates_email_address_of.rb', line 7

def default_options
  @default_options ||= {:format => true, :mx => true, :smtp => true, :message => "invalid email address"}
end

#validate_each(record, attribute, value) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/validates_email_address_of.rb', line 11

def validate_each (record, attribute, value)
  options = default_options.merge(self.options)

  if options[:format] && check_format(value) == false
    record.errors.add(attribute, options[:message])
    return
  end

  if options[:mx] && check_mx(value) == false
    record.errors.add(attribute, options[:message])
    return
  end

  if options[:smtp] && check_smtp(value) == false
    record.errors.add(attribute, options[:message])
  end

end