Class: Pact::Consumer::SetLocation
- Inherits:
-
Object
- Object
- Pact::Consumer::SetLocation
- Defined in:
- lib/pact/consumer/mock_service/set_location.rb
Constant Summary collapse
- LOCATION =
'X-Pact-Mock-Service-Location'.freeze
- HTTP_X_PACT_MOCK_SERVICE =
'HTTP_X_PACT_MOCK_SERVICE'
Instance Method Summary collapse
- #add_location_header_to_response(response) ⇒ Object
- #call(env) ⇒ Object
-
#initialize(app, base_url) ⇒ SetLocation
constructor
A new instance of SetLocation.
- #shutdown ⇒ Object
Constructor Details
#initialize(app, base_url) ⇒ SetLocation
Returns a new instance of SetLocation.
8 9 10 11 |
# File 'lib/pact/consumer/mock_service/set_location.rb', line 8 def initialize app, base_url @app = app @location_header = {LOCATION => base_url}.freeze end |
Instance Method Details
#add_location_header_to_response(response) ⇒ Object
18 19 20 |
# File 'lib/pact/consumer/mock_service/set_location.rb', line 18 def add_location_header_to_response response [response.first, response[1].merge(@location_header), response.last] end |
#call(env) ⇒ Object
13 14 15 16 |
# File 'lib/pact/consumer/mock_service/set_location.rb', line 13 def call env response = @app.call(env) env[HTTP_X_PACT_MOCK_SERVICE] ? add_location_header_to_response(response) : response end |
#shutdown ⇒ Object
22 23 24 |
# File 'lib/pact/consumer/mock_service/set_location.rb', line 22 def shutdown @app.shutdown end |