Sha256: 730bb93c8ac8b5143e1c90491d9d08f4b918f9747ff0b52bea8ece6e71e7b8d4

Contents?: true

Size: 777 Bytes

Versions: 71

Compression:

Stored size: 777 Bytes

Contents

require 'set'
require 'vcr/util/hooks'

module VCR
  # @private
  class RequestIgnorer
    include VCR::Hooks

    define_hook :ignore_request

    LOCALHOST_ALIASES = %w( localhost 127.0.0.1 0.0.0.0 )

    def initialize
      ignore_request do |request|
        host = request.parsed_uri.host
        ignored_hosts.include?(host)
      end
    end

    def ignore_localhost=(value)
      if value
        ignore_hosts(*LOCALHOST_ALIASES)
      else
        ignored_hosts.reject! { |h| LOCALHOST_ALIASES.include?(h) }
      end
    end

    def ignore_hosts(*hosts)
      ignored_hosts.merge(hosts)
    end

    def ignore?(request)
      invoke_hook(:ignore_request, request).any?
    end

  private

    def ignored_hosts
      @ignored_hosts ||= Set.new
    end
  end
end

Version data entries

71 entries across 71 versions & 9 rubygems

Version Path
vcr-2.9.3 lib/vcr/request_ignorer.rb
vcr-2.9.2 lib/vcr/request_ignorer.rb
vcr-2.9.1 lib/vcr/request_ignorer.rb
vcr-2.9.0 lib/vcr/request_ignorer.rb
social_url_stats-0.0.1 vendor/ruby/1.9.1/gems/vcr-2.8.0/lib/vcr/request_ignorer.rb
vcr-2.8.0 lib/vcr/request_ignorer.rb
vcr-2.7.0 lib/vcr/request_ignorer.rb
vcr-2.6.0 lib/vcr/request_ignorer.rb
vcr-2.5.0 lib/vcr/request_ignorer.rb
vcr-2.4.0 lib/vcr/request_ignorer.rb
vcr-2.3.0 lib/vcr/request_ignorer.rb