Class: EmailFormatValidator

Inherits:
ActiveModel::EachValidator
  • Object
show all
Defined in:
app/validators/email_format_validator.rb

Overview

Validates that an email address (or array of addresses) passes Truemail verification.

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ void

This method returns an undefined value.

Validates a single attribute value (or each element of an array) with Truemail.

Parameters:

  • record (ActiveModel::Model)

    the record being validated

  • attribute (Symbol)

    the attribute name

  • value (String, Array<String>, nil)

    the email address(es) to validate



11
12
13
14
15
# File 'app/validators/email_format_validator.rb', line 11

def validate_each(record, attribute, value)
  [value].flatten.filter_map(&:presence).each do |v|
    record.errors.add attribute, (options[:message] || "#{v} is not a valid email") unless Truemail.valid?(v)
  end
end