Class: SequenceServer::Server

Inherits:
Object
  • Object
show all
Defined in:
lib/sequenceserver/server.rb

Overview

Simple wrapper around WEBrick and Rack::Handler::WEBrick to host SequenceServer standalone.

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(app) ⇒ Server

Returns a new instance of Server.



13
14
15
# File 'lib/sequenceserver/server.rb', line 13

def initialize(app)
  @app = app
end

Instance Attribute Details

#appObject (readonly)

Returns the value of attribute app.



17
18
19
# File 'lib/sequenceserver/server.rb', line 17

def app
  @app
end

Class Method Details

.run(*args) ⇒ Object



8
9
10
# File 'lib/sequenceserver/server.rb', line 8

def run(*args)
  new(*args).start
end

Instance Method Details

#optionsObject

Options Hash passed to WEBrick::HTTPServer. rubocop:disable Metrics/AbcSize



36
37
38
39
40
41
42
43
44
45
46
# File 'lib/sequenceserver/server.rb', line 36

def options
  @options ||= {
    BindAddress:      app.config[:host],
    Port:             app.config[:port],
    StartCallback:    proc { app.on_start },
    StopCallback:     proc { app.on_stop  },
    OutputBufferSize: 5,
    AccessLog:        [[logdev, WEBrick::AccessLog::COMMON_LOG_FORMAT]],
    Logger:           WEBrick::Log.new(logdev)
  }
end

#startObject

Start server. Raises Errno::EADDRINUSE if port is in use by another process. Raises Errno::EACCES if binding to the port requires root privilege.



22
23
24
25
26
27
# File 'lib/sequenceserver/server.rb', line 22

def start
  setup_signal_handlers
  @server = WEBrick::HTTPServer.new(options)
  @server.mount '/', Rack::Handler::WEBrick, app
  @server.start
end

#stopObject

Stop server.



30
31
32
# File 'lib/sequenceserver/server.rb', line 30

def stop
  @server.shutdown
end