Class: Pact::MockService::RequestHandlers::BaseRequestHandler

Inherits:
Object
  • Object
show all
Includes:
Consumer::RackRequestHelper
Defined in:
lib/pact/mock_service/request_handlers/base_request_handler.rb

Constant Summary collapse

NOT_FOUND_RESPONSE =
[404, {}, []].freeze

Constants included from Consumer::RackRequestHelper

Consumer::RackRequestHelper::REQUEST_KEYS

Instance Method Summary collapse

Methods included from Consumer::RackRequestHelper

#params_hash, #request_as_hash_from

Instance Method Details

#call(env) ⇒ Object



16
17
18
# File 'lib/pact/mock_service/request_handlers/base_request_handler.rb', line 16

def call env
  match?(env) ? respond(env) : NOT_FOUND_RESPONSE
end

#json_response(json = nil, status = 200) ⇒ Object



20
21
22
# File 'lib/pact/mock_service/request_handlers/base_request_handler.rb', line 20

def json_response json = nil, status = 200
  [status, {'Content-Type' => 'application/json'}, json ? [json + "\n"]: []]
end

#match?(env) ⇒ Boolean

Returns:

  • (Boolean)

Raises:

  • (NotImplementedError)


12
13
14
# File 'lib/pact/mock_service/request_handlers/base_request_handler.rb', line 12

def match? env
  raise NotImplementedError
end

#text_response(text = nil, status = 200) ⇒ Object



24
25
26
# File 'lib/pact/mock_service/request_handlers/base_request_handler.rb', line 24

def text_response text = nil, status = 200
  [status, {'Content-Type' => 'text/plain'}, text ? [text + "\n"]: []]
end