Sha256: 72715698e3130cc698352c65d5729e85aaa674a6c33885b026a29e8ca630e04b

Contents?: true

Size: 1005 Bytes

Versions: 2

Compression:

Stored size: 1005 Bytes

Contents

module VCR
  class RequestHandler
    def handle
      return on_ignored_request    if should_ignore?
      return on_stubbed_request    if stubbed_response
      return on_recordable_request if VCR.real_http_connections_allowed?
      on_connection_not_allowed
    end

  private

    def should_ignore?
      disabled? || VCR.request_ignorer.ignore?(vcr_request)
    end

    def disabled?
      VCR.library_hooks.disabled?(library_name)
    end

    def stubbed_response
      @stubbed_response ||= VCR.http_interactions.response_for(vcr_request)
    end

    def library_name
      # extracts `:typhoeus` from `VCR::LibraryHooks::Typhoeus::RequestHandler`
      @library_name ||= self.class.name.split('::')[-2].downcase.to_sym
    end

    # Subclasses can implement these
    def on_ignored_request
    end

    def on_stubbed_request
    end

    def on_recordable_request
    end

    def on_connection_not_allowed
      raise VCR::HTTPConnectionNotAllowedError.new(vcr_request)
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
vcr-2.0.0.beta2 lib/vcr/request_handler.rb
vcr-2.0.0.beta1 lib/vcr/request_handler.rb