class Truemail::Validator

Constants

RESULT_ATTRS
Result
VALIDATION_TYPES

Attributes

validation_type[R]

Public Class Methods

new(email, configuration:, with: nil) click to toggle source
# File lib/truemail/validator.rb, line 21
def initialize(email, configuration:, with: nil)
  with ||= configuration.default_validation_type
  raise Truemail::ArgumentError.new(with, :argument) unless Truemail::Validator::VALIDATION_TYPES.include?(with)
  @result = Truemail::Validator::Result.new(email: email, configuration: configuration)
  @validation_type = select_validation_type(email, with)
end

Public Instance Methods

as_json() click to toggle source
# File lib/truemail/validator.rb, line 35
def as_json
  Truemail::Log::Serializer::ValidatorJson.call(self)
end
run() click to toggle source
# File lib/truemail/validator.rb, line 28
def run
  Truemail::Validate::DomainListMatch.check(result)
  result_not_changed? ? Truemail::Validate.const_get(constantize(validation_type)).check(result) : update_validation_type
  logger&.push(self)
  self
end

Private Instance Methods

constantize(symbol) click to toggle source
# File lib/truemail/validator.rb, line 46
def constantize(symbol)
  symbol.capitalize.to_s.gsub(/_[a-z]/, &:upcase).tr('_', '').to_sym
end
logger() click to toggle source
# File lib/truemail/validator.rb, line 62
def logger
  result.configuration.logger
end
result_not_changed?() click to toggle source
# File lib/truemail/validator.rb, line 58
def result_not_changed?
  result_status.nil?
end
result_status() click to toggle source
# File lib/truemail/validator.rb, line 54
def result_status
  result.success
end
select_validation_type(email, current_validation_type) click to toggle source
# File lib/truemail/validator.rb, line 41
def select_validation_type(email, current_validation_type)
  domain = email[Truemail::RegexConstant::REGEX_EMAIL_PATTERN, 3]
  result.configuration.validation_type_by_domain[domain] || current_validation_type
end
update_validation_type() click to toggle source
# File lib/truemail/validator.rb, line 50
def update_validation_type
  @validation_type = result.success ? :whitelist : :blacklist
end