Class: EmailCcValidator

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

Overview

An ActiveRecord validator for any email field that you would use with effective_email or otherwise

validates :cc, email_cc: true

Constant Summary collapse

PATTERN =
/\A.+@.+\..+\Z/

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



8
9
10
11
12
13
14
# File 'lib/validators/email_cc_validator.rb', line 8

def validate_each(record, attribute, value)
  if value.present?
    unless value.to_s.split(',').all? { |email| PATTERN =~ email }
      record.errors.add(attribute, 'is invalid')
    end
  end
end