Class: Pact::MockService::ControlServer::MockServiceCreator

Inherits:
Object
  • Object
show all
Defined in:
lib/pact/mock_service/control_server/mock_service_creator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(mock_services, options) ⇒ MockServiceCreator

Returns a new instance of MockServiceCreator.



15
16
17
18
# File 'lib/pact/mock_service/control_server/mock_service_creator.rb', line 15

def initialize mock_services, options
  @mock_services = mock_services
  @options = options
end

Instance Attribute Details

#optionsObject (readonly)

Returns the value of attribute options.



13
14
15
# File 'lib/pact/mock_service/control_server/mock_service_creator.rb', line 13

def options
  @options
end

Instance Method Details

#call(env) ⇒ Object



20
21
22
23
24
25
26
27
28
# File 'lib/pact/mock_service/control_server/mock_service_creator.rb', line 20

def call env
  consumer_name = env['HTTP_X_PACT_CONSUMER']
  provider_name = env['HTTP_X_PACT_PROVIDER']
  port = FindAPort.available_port
  mock_service = Pact::MockService::Spawn.(consumer_name, provider_name, options[:host] || 'localhost', port, options)
  delegator = Delegator.new(mock_service, consumer_name, provider_name)
  @mock_services.add(delegator)
  delegator.call(env)
end