Sha256: bb1344fa41e331aa01d3678c7cd08170f31fb2e61f77bbe2ac2786004e27924a

Contents?: true

Size: 1.44 KB

Versions: 18

Compression:

Stored size: 1.44 KB

Contents

require 'vcr/middleware/faraday'

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

        ::Faraday::Builder.extend self
      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

18 entries across 18 versions & 3 rubygems

Version Path
dwolla_swagger-1.0.6 vendor/bundle/ruby/2.2.0/gems/vcr-2.9.3/lib/vcr/library_hooks/faraday.rb
vcr-2.9.3 lib/vcr/library_hooks/faraday.rb
vcr-2.9.2 lib/vcr/library_hooks/faraday.rb
vcr-2.9.1 lib/vcr/library_hooks/faraday.rb
vcr-2.9.0 lib/vcr/library_hooks/faraday.rb
social_url_stats-0.0.1 vendor/ruby/1.9.1/gems/vcr-2.8.0/lib/vcr/library_hooks/faraday.rb
vcr-2.8.0 lib/vcr/library_hooks/faraday.rb
vcr-2.7.0 lib/vcr/library_hooks/faraday.rb
vcr-2.6.0 lib/vcr/library_hooks/faraday.rb
vcr-2.5.0 lib/vcr/library_hooks/faraday.rb
vcr-2.4.0 lib/vcr/library_hooks/faraday.rb
vcr-2.3.0 lib/vcr/library_hooks/faraday.rb
vcr-2.2.5 lib/vcr/library_hooks/faraday.rb
vcr-2.2.4 lib/vcr/library_hooks/faraday.rb
vcr-2.2.3 lib/vcr/library_hooks/faraday.rb
vcr-2.2.2 lib/vcr/library_hooks/faraday.rb
vcr-2.2.1 lib/vcr/library_hooks/faraday.rb
vcr-2.2.0 lib/vcr/library_hooks/faraday.rb