Module: ActiveRecord::Validations::ClassMethods

Defined in:
lib/validates_as_email.rb

Instance Method Summary collapse

Instance Method Details

#validates_as_email(*attr_names) ⇒ Object



61
62
63
64
65
66
67
68
69
70
71
# File 'lib/validates_as_email.rb', line 61

def validates_as_email(*attr_names)
  options = attr_names.pop if attr_names.last.is_a?(Hash)
  restrict_domain = options.delete(:restrict_domain) if options
  configuration = {
    :message   => (I18n.translate(:'activerecord.errors.messages.invalid_email', :raise => true) rescue 'is an invalid email'),
    :with      => restrict_domain ? RFC822::NonLocalEmailAddress : RFC822::EmailAddress,
    :allow_nil => false }
  configuration.update(options) if options

  validates_format_of attr_names, configuration
end