Class: Truemail::Validator

Inherits:
Object
  • Object
show all
Defined in:
lib/truemail/validator.rb

Defined Under Namespace

Classes: Result

Constant Summary collapse

RESULT_ATTRS =
%i[success email domain mail_servers errors smtp_debug configuration].freeze
VALIDATION_TYPES =
%i[regex mx smtp].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(email, with: nil, configuration:) ⇒ Validator

Returns a new instance of Validator.



17
18
19
20
21
22
# File 'lib/truemail/validator.rb', line 17

def initialize(email, with: nil, configuration:)
  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

Instance Attribute Details

#resultObject (readonly)

Returns the value of attribute result.



15
16
17
# File 'lib/truemail/validator.rb', line 15

def result
  @result
end

#validation_typeObject (readonly)

Returns the value of attribute validation_type.



15
16
17
# File 'lib/truemail/validator.rb', line 15

def validation_type
  @validation_type
end

Instance Method Details

#runObject



24
25
26
27
28
29
# File 'lib/truemail/validator.rb', line 24

def run
  Truemail::Validate::DomainListMatch.check(result)
  result_not_changed? ? Truemail::Validate.const_get(validation_type.capitalize).check(result) : update_validation_type
  logger&.push(self)
  self
end