Sha256: dafd063e44e3200116eb23d76afcf5f552ab3a88c613b3e888c744c232ab4bd0

Contents?: true

Size: 1.04 KB

Versions: 1

Compression:

Stored size: 1.04 KB

Contents

# frozen_string_literal: true

module DevSuite
  module RequestLogger
    module Adapter
      require_relative "middleware/faraday"

      class Faraday < Base
        def enable
          ::Faraday::Connection.class_eval do
            alias_method(:_original_run_request, :run_request)

            def run_request(method, url, body, headers, &block)
              env = ::Faraday::Env.new(method, url, body, headers)
              env.request = @request
              env.params = @params
              env.request_body = @request_body
              env.ssl = @ssl
              env.response = @response

              Middleware::Faraday.new(lambda do |e|
                _original_run_request(e.method, e.url, e.body, e.request_headers, &block)
              end).call(env, self)
            end
          end
        end

        def disable
          ::Faraday::Connection.class_eval do
            alias_method(:run_request, :_original_run_request)
            remove_method(:_original_run_request)
          end
        end
      end
    end
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
dev_suite-0.2.8 lib/dev_suite/request_logger/adapter/faraday.rb