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].freeze
VALIDATION_TYPES =
%i[regex mx smtp].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(email, with: Truemail.configuration.default_validation_type) ⇒ Validator

Returns a new instance of Validator.



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

def initialize(email, with: Truemail.configuration.default_validation_type)
  raise Truemail::ArgumentError.new(with, :argument) unless Truemail::Validator::VALIDATION_TYPES.include?(with)
  @validation_type = select_validation_type(email, with)
  @result = Truemail::Validator::Result.new(email: email)
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



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

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