Class: Pact::MockService::ControlServer::Run

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

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(options) ⇒ Run

Returns a new instance of Run.



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

def initialize options
  @options = options
end

Class Method Details

.call(options) ⇒ Object



9
10
11
# File 'lib/pact/mock_service/control_server/run.rb', line 9

def self.call options
  new(options).call
end

Instance Method Details

#callObject



17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/pact/mock_service/control_server/run.rb', line 17

def call
  trap(:INT) { shutdown }
  trap(:TERM) { shutdown }

  # https://github.com/rack/rack/blob/ae78184e5c1fcf4ac133171ed4b47b0548cd9b44/lib/rack/handler/webrick.rb#L32
  # Rack adapter for webrick uses class variable for the server which contains the port,
  # so if we use it more than once in the same process, we lose the reference to the first
  # server, and can't shut it down. So, keep a manual reference to the Webrick server, and
  # shut it down directly rather than use Rack::Handler::WEBrick.shutdown
  # Ruby!
  Rack::Handler::WEBrick.run(control_server, **webbrick_opts) do | server |
    @webrick_server = server
  end
end