Sha256: 609ab1fa2e55ea264decf48c6778748fd9a230da28f456a2fa9f058158140a49

Contents?: true

Size: 1.14 KB

Versions: 1

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

module ActiveRecordMysqlXverify
  module Verifier
    def active?
      if _extend_verify?
        is_active = begin
          verifier = ActiveRecordMysqlXverify.verify
          verifier.call(@connection)
        rescue StandardError => e
          ActiveRecordMysqlXverify.logger.warn("Connection verification failed: #{_build_verify_error_message(e)}")
          false
        ensure
          Thread.current[ActiveRecordMysqlXverify::EXTEND_VERIFY_FLAG] = false
        end

        unless is_active
          ActiveRecordMysqlXverify.logger.info(
            "Invalid connection: #{ActiveRecordMysqlXverify::Utils.mysql2_connection_info(@connection)}"
          )
        end

        is_active
      else
        super
      end
    end

    def _build_verify_error_message(e)
      "cause: #{e.message} [#{e.class}, " + ActiveRecordMysqlXverify::Utils.mysql2_connection_info(@connection)
    end

    def _extend_verify?
      handle_if = ActiveRecordMysqlXverify.handle_if
      (!ActiveRecordMysqlXverify.only_on_error || Thread.current[ActiveRecordMysqlXverify::EXTEND_VERIFY_FLAG]) && handle_if.call(@config)
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
active_record_mysql_xverify-0.3.0 lib/active_record_mysql_xverify/verifier.rb