Sha256: 7574d5d787bf4caf72912abd191cb6e3ca9ff65af1f73e6e6ee476b9a430e1bf

Contents?: true

Size: 1.35 KB

Versions: 3

Compression:

Stored size: 1.35 KB

Contents

# frozen_string_literal: true

module Truemail
  module Log
    module Serializer
      class ValidatorBase < Truemail::Log::Serializer::Base
        def initialize(executor_instance)
          @validation_type = executor_instance.validation_type
          super
        end

        private

        attr_reader :validation_type

        def replace_invalid_chars
          ->(value) { value.encode('UTF-8', invalid: :replace) }
        end

        def smtp_debug
          validation_smtp_debug = executor_result.smtp_debug
          return unless validation_smtp_debug
          validation_smtp_debug.map do |smtp_request|
            smtp_response = smtp_request.response
            {
              mail_host: smtp_request.host,
              port_opened: smtp_response.port_opened,
              connection: smtp_response.connection,
              errors: smtp_response.errors.transform_values(&replace_invalid_chars)
            }
          end
        end

        def result
          @result ||=
            {
              date: Time.now,
              email: executor_result.email,
              validation_type: validation_type,
              success: executor_result.success,
              errors: errors(executor_result.errors),
              smtp_debug: smtp_debug,
              configuration: configuration
            }
        end
      end
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
truemail-2.2.3 lib/truemail/log/serializer/validator_base.rb
truemail-2.2.2 lib/truemail/log/serializer/validator_base.rb
truemail-2.2.1 lib/truemail/log/serializer/validator_base.rb