Class: EmailValidator

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#attributeObject (readonly)

Returns the value of attribute attribute.



6
7
8
# File 'lib/trogdir/validators/email_validator.rb', line 6

def attribute
  @attribute
end

#emailObject (readonly)

Returns the value of attribute email.



6
7
8
# File 'lib/trogdir/validators/email_validator.rb', line 6

def email
  @email
end

#recordObject (readonly)

Returns the value of attribute record.



6
7
8
# File 'lib/trogdir/validators/email_validator.rb', line 6

def record
  @record
end

#treeObject (readonly)

Returns the value of attribute tree.



6
7
8
# File 'lib/trogdir/validators/email_validator.rb', line 6

def tree
  @tree
end

#valueObject (readonly)

Returns the value of attribute value.



6
7
8
# File 'lib/trogdir/validators/email_validator.rb', line 6

def value
  @value
end

Instance Method Details

#validate_each(record, attribute, value) ⇒ Object



8
9
10
11
12
13
14
15
16
17
# File 'lib/trogdir/validators/email_validator.rb', line 8

def validate_each(record, attribute, value)
  @record, @attribute, @value = record, attribute, value

  @email = Mail::Address.new(value)
  @tree  = email.__send__(:tree)

  add_error unless valid?
rescue Mail::Field::ParseError
  add_error
end