1class EmailValidator < ActiveModel::EachValidator
 
2  EMAIL_REGEX = /\A[^@\s]+@[^@\s]+\.[^@\s]+\z/
 
3
  • DuplicateMethodCall - calls 'record.errors' 3 times » reek
  • DuplicateMethodCall - calls 'record.errors.add attribute, :invalid' 2 times » reek
  • FeatureEnvy - refers to 'record' more than self (maybe move it to another class?) » reek
  • Complexity 4 » saikuro
4  def validate_each(record, attribute, value)
 
5    if value =~ EMAIL_REGEX
 
6      email = parsed_email(value)
 
7      record.errors.add attribute, :plus_address if plus_address?(email)
 
8    else
 
 9      record.errors.add attribute, :invalid
 
10    end
 
11  rescue Mail::Field::ParseError
 
12    record.errors.add attribute, :invalid
 
13  end
 
  • UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
  • Complexity 2 » saikuro
15  def plus_address?(parsed_email)
 
16    unless Site.disable_plus_address_check?
 
17      parsed_email.local.include? '+'
 
18    end
 
19  end
 
  • UtilityFunction - doesn't depend on instance state (maybe move it to another class?) » reek
  • Complexity 1 » saikuro
21  def parsed_email(email)
 
22    Mail::Address.new(email)
 
23  end
 
24end