Updated

app/validators / email_validator.rb

A
24 lines of codes
3 methods
5.6 complexity/method
4 churn
16.8 complexity
0 duplications
class EmailValidator < ActiveModel::EachValidator
  1. EmailValidator has no descriptive comment
EMAIL_REGEX = /\A[^@\s]+@[^@\s]+\.[^@\s]+\z/ def validate_each(record, attribute, value) if value =~ EMAIL_REGEX email = parsed_email(value) record.errors.add attribute, :plus_address if plus_address?(email)
  1. EmailValidator#validate_each calls 'record.errors' 3 times Locations: 0 1 2
  2. EmailValidator#validate_each refers to 'record' more than self (maybe move it to another class?) Locations: 0 1 2
else record.errors.add attribute, :invalid
  1. EmailValidator#validate_each calls 'record.errors' 3 times Locations: 0 1 2
  2. EmailValidator#validate_each calls 'record.errors.add attribute, :invalid' 2 times Locations: 0 1
  3. EmailValidator#validate_each refers to 'record' more than self (maybe move it to another class?) Locations: 0 1 2
end rescue Mail::Field::ParseError record.errors.add attribute, :invalid
  1. EmailValidator#validate_each calls 'record.errors' 3 times Locations: 0 1 2
  2. EmailValidator#validate_each calls 'record.errors.add attribute, :invalid' 2 times Locations: 0 1
  3. EmailValidator#validate_each refers to 'record' more than self (maybe move it to another class?) Locations: 0 1 2
end def plus_address?(parsed_email)
  1. EmailValidator#plus_address? doesn't depend on instance state (maybe move it to another class?)
unless Site.disable_plus_address_check? parsed_email.local.include? '+' end end def parsed_email(email)
  1. EmailValidator#parsed_email doesn't depend on instance state (maybe move it to another class?)
Mail::Address.new(email) end end