Class: VCR::HeaderMatcher

Inherits:
Struct
  • Object
show all
Defined in:
lib/vcr/header_matcher.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#keysObject

Returns the value of attribute keys

Returns:

  • (Object)

    the current value of keys



2
3
4
# File 'lib/vcr/header_matcher.rb', line 2

def keys
  @keys
end

Instance Method Details

#human_typeObject



34
35
36
# File 'lib/vcr/header_matcher.rb', line 34

def human_type
  ""
end

#matches?(request, expected_request) ⇒ Boolean

Returns:

  • (Boolean)


3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/vcr/header_matcher.rb', line 3

def matches?(request, expected_request)
  requested_headers = request.headers
  expected_headers = expected_request.headers

  if only_keys.present?
    requested_headers.slice!(*only_keys)
    expected_headers.slice!(*only_keys)
  end

  if  without_keys.present?
    requested_headers.except!(*without_keys)
    expected_headers.except!(*without_keys)
  end

  requested_headers == expected_headers
end

#only_keysObject



27
28
29
30
31
32
# File 'lib/vcr/header_matcher.rb', line 27

def only_keys
  keys.map do |k|
    prefix, key_name = k.split(/^\^/)
    prefix if prefix.present?
  end.compact
end

#without_keysObject



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

def without_keys
  keys.map do |k|
    prefix, key_name = k.split(/^\^/)
    key_name if key_name.present?
  end.compact
end