Class: AliasValidator

Inherits:
EmailValidator
  • Object
show all
Defined in:
app/validators/alias_validator.rb

Overview

Validates that a string contains only valid email addresses, separated by comma

Instance Method Summary collapse

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



3
4
5
6
7
8
9
10
11
12
# File 'app/validators/alias_validator.rb', line 3

def validate_each(record, attribute, value)
  destinations = value.split(", ")
  unless destinations.map {|destination| self.class.valid?(destination) }.all?
    record.errors[attribute] << (options[:message] || "is not a valid list of email addresses")
  end
  existing = VirtualAlias.where(source: record.source, destination: record.destination).count
  if existing != 0
    record.errors[attribute] << (options[:message] || "is already present")
  end
end