Class: Webspicy::Web::Specification::Pre::GlobalRequestHeaders

Inherits:
Object
  • Object
show all
Includes:
Webspicy::Web::Specification::Pre
Defined in:
lib/webspicy/web/specification/pre/global_request_headers.rb

Constant Summary collapse

DEFAULT_OPTIONS =
{}

Constants included from Specification::Condition

Specification::Condition::MATCH_ALL

Instance Attribute Summary collapse

Attributes included from Specification::Condition

#matching_description, #tester

Instance Method Summary collapse

Methods included from Specification::Pre

#contribute_to_openapi_verb, #counterexamples

Methods included from Specification::Condition

#bind, #fail!, match, #sooner_or_later, #to_s

Constructor Details

#initialize(headers, options = {}, &bl) ⇒ GlobalRequestHeaders

Returns a new instance of GlobalRequestHeaders.



10
11
12
13
14
# File 'lib/webspicy/web/specification/pre/global_request_headers.rb', line 10

def initialize(headers, options = {}, &bl)
  @headers = headers
  @options = DEFAULT_OPTIONS.merge(options)
  @matcher = bl
end

Instance Attribute Details

#headersObject (readonly)

Returns the value of attribute headers.



15
16
17
# File 'lib/webspicy/web/specification/pre/global_request_headers.rb', line 15

def headers
  @headers
end

#matcherObject (readonly)

Returns the value of attribute matcher.



15
16
17
# File 'lib/webspicy/web/specification/pre/global_request_headers.rb', line 15

def matcher
  @matcher
end

Instance Method Details

#instrumentObject



26
27
28
29
30
31
32
# File 'lib/webspicy/web/specification/pre/global_request_headers.rb', line 26

def instrument
  extra = headers.reject{|k|
    test_case.headers.has_key?(k)
  }
  puts "Instrumenting #{test_case.object_id}"
  test_case.headers.merge!(extra)
end

#match(service, pre) ⇒ Object



17
18
19
20
21
22
23
24
# File 'lib/webspicy/web/specification/pre/global_request_headers.rb', line 17

def match(service, pre)
  if matcher
    return self if matcher.call(service)
    nil
  else
    self
  end
end