Class: EmailValidator

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

Overview

global namespace so you can use the rails 3 “validate :field, email: [options]”

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/email_attribute/email_validator.rb', line 3

def validate_each(record,attribute,value)
  return if value.blank? && options[:allow_blank]

  case value
  when EmailAttribute::SingleAddress
    validate_single_address_model(record, attribute, value.address)
  when String
    validate_single_address_model(record, attribute, value)
  when EmailAttribute::List
    value.each do |address|
      validate_single_address_model(record, attribute, address)
    end
  end
end