Class: VCR::RequestIgnorer

Inherits:
Object
  • Object
show all
Includes:
Hooks
Defined in:
lib/vcr/request_ignorer.rb

Constant Summary collapse

LOCALHOST_ALIASES =
%w( localhost 127.0.0.1 0.0.0.0 )

Instance Method Summary collapse

Methods included from Hooks

#clear_hooks, #has_hooks_for?, #hooks, included, #invoke_hook

Methods included from VariableArgsBlockCaller

#call_block

Constructor Details

#initializeRequestIgnorer

Returns a new instance of RequestIgnorer.



13
14
15
16
17
18
# File 'lib/vcr/request_ignorer.rb', line 13

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

Instance Method Details

#ignore?(request) ⇒ Boolean

Returns:

  • (Boolean)


40
41
42
# File 'lib/vcr/request_ignorer.rb', line 40

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

#ignore_hosts(*hosts) ⇒ Object



32
33
34
# File 'lib/vcr/request_ignorer.rb', line 32

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

#ignore_localhost=(value) ⇒ Object



20
21
22
23
24
25
26
# File 'lib/vcr/request_ignorer.rb', line 20

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

#localhost_ignored?Boolean

Returns:

  • (Boolean)


28
29
30
# File 'lib/vcr/request_ignorer.rb', line 28

def localhost_ignored?
  (LOCALHOST_ALIASES & ignore_hosts.to_a).any?
end

#unignore_hosts(*hosts) ⇒ Object



36
37
38
# File 'lib/vcr/request_ignorer.rb', line 36

def unignore_hosts(*hosts)
  ignored_hosts.subtract(hosts)
end