Class: Truemail::Validator

Inherits:
Executor 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

Attributes inherited from Executor

#result

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Validator.


21
22
23
24
25
26
# File 'lib/truemail/validator.rb', line 21

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

#validation_typeObject (readonly)

Returns the value of attribute validation_type


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

def validation_type
  @validation_type
end

Instance Method Details

#as_jsonObject


35
36
37
# File 'lib/truemail/validator.rb', line 35

def as_json
  Truemail::Log::Serializer::ValidatorJson.call(self)
end

#runObject


28
29
30
31
32
33
# File 'lib/truemail/validator.rb', line 28

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