Class: SequenceServer::Server
- Inherits:
-
Object
- Object
- SequenceServer::Server
- Defined in:
- lib/sequenceserver/server.rb
Overview
Simple wrapper around WEBrick and Rack::Handler::WEBrick to host SequenceServer standalone.
Instance Attribute Summary collapse
-
#app ⇒ Object
readonly
Returns the value of attribute app.
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(app) ⇒ Server
constructor
A new instance of Server.
-
#options ⇒ Object
Options Hash passed to WEBrick::HTTPServer.
-
#start ⇒ Object
Start server.
-
#stop ⇒ Object
Stop server.
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
#app ⇒ Object (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
#options ⇒ Object
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 ||= { 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 |
#start ⇒ Object
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() @server.mount '/', Rack::Handler::WEBrick, app @server.start end |
#stop ⇒ Object
Stop server.
30 31 32 |
# File 'lib/sequenceserver/server.rb', line 30 def stop @server.shutdown end |