Sha256: e985dc32f3fe6d4f05723e05923d66ce2ad2116d8fc0350404b368308238cae6

Contents?: true

Size: 1.56 KB

Versions: 68

Compression:

Stored size: 1.56 KB

Contents

require 'vcr/middleware/faraday'

module VCR
  class LibraryHooks
    # @private
    module Faraday
      # @private
      module BuilderClassExtension
        def new(*args)
          super.extend BuilderInstanceExtension
        end

        if defined?(::Faraday::RackBuilder)
          ::Faraday::RackBuilder.extend self
        else
          ::Faraday::Builder.extend self
        end
      end

      # @private
      module BuilderInstanceExtension
        def lock!(*args)
          insert_vcr_middleware
          super
        end

      private

        def insert_vcr_middleware
          return if handlers.any? { |h| h.klass == VCR::Middleware::Faraday }
          adapter_index = handlers.index { |h| h.klass < ::Faraday::Adapter }
          adapter_index ||= handlers.size
          warn_about_after_adapter_middleware(adapter_index)
          insert_before(adapter_index, VCR::Middleware::Faraday)
        end

        def warn_about_after_adapter_middleware(adapter_index)
          after_adapter_middleware_count = (handlers.size - adapter_index - 1)
          return if after_adapter_middleware_count < 1

          after_adapter_middlewares = handlers.last(after_adapter_middleware_count)
          warn "WARNING: The Faraday connection stack contains middleware after " +
               "the HTTP adapter (#{after_adapter_middlewares.map(&:inspect).join(', ')}). " +
               "This is a non-standard configuration and VCR may not be able to " +
               "record the HTTP requests made through this Faraday connection."
        end
      end
    end
  end
end

Version data entries

68 entries across 68 versions & 9 rubygems

Version Path
docspring-3.0.0 vendor/bundle/ruby/3.3.0/gems/vcr-3.0.3/lib/vcr/library_hooks/faraday.rb
cloudsmith-api-2.0.16 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/lib/vcr/library_hooks/faraday.rb
cloudsmith-api-2.0.15 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/lib/vcr/library_hooks/faraday.rb
cloudsmith-api-2.0.14 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/lib/vcr/library_hooks/faraday.rb
vcr-6.3.1 lib/vcr/library_hooks/faraday.rb
vcr-6.3.0 lib/vcr/library_hooks/faraday.rb
cloudsmith-api-2.0.13 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/lib/vcr/library_hooks/faraday.rb
cloudsmith-api-2.0.12 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/lib/vcr/library_hooks/faraday.rb
cloudsmith-api-2.0.11 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/lib/vcr/library_hooks/faraday.rb
cloudsmith-api-2.0.10 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/lib/vcr/library_hooks/faraday.rb
cloudsmith-api-2.0.9 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/lib/vcr/library_hooks/faraday.rb
cloudsmith-api-2.0.8 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/lib/vcr/library_hooks/faraday.rb
cloudsmith-api-2.0.7 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/lib/vcr/library_hooks/faraday.rb
vcr-6.2.0 lib/vcr/library_hooks/faraday.rb
cloudsmith-api-2.0.6 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/lib/vcr/library_hooks/faraday.rb
cloudsmith-api-2.0.5 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/lib/vcr/library_hooks/faraday.rb
cloudsmith-api-2.0.4 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/lib/vcr/library_hooks/faraday.rb
cloudsmith-api-2.0.3 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/lib/vcr/library_hooks/faraday.rb
cloudsmith-api-2.0.2 vendor/bundle/ruby/2.6.0/gems/vcr-3.0.3/lib/vcr/library_hooks/faraday.rb
fluent-plugin-google-cloud-logging-on-prem-0.1.0 vendor/ruby/3.1.0/gems/vcr-6.1.0/lib/vcr/library_hooks/faraday.rb