Class: MotherBrain::RestGateway
- Inherits:
-
Reel::Rack::Server
- Object
- Reel::Rack::Server
- MotherBrain::RestGateway
- Includes:
- Logging
- Defined in:
- lib/mb/rest_gateway.rb
Constant Summary collapse
- DEFAULT_PORT =
ENV["PORT"] ? ENV["PORT"].to_i : 26100
- DEFAULT_OPTIONS =
{ host: '0.0.0.0', port: DEFAULT_PORT, quiet: false }.freeze
- VALID_OPTIONS =
[ :host, :port, :quiet ].freeze
Class Method Summary collapse
- .instance ⇒ Celluloid::Actor(Gateway)
-
.start(options = {}) ⇒ Object
Start the REST Gateway and add it to the application’s registry.
-
.stop ⇒ Object
Stop the currently running REST Gateway.
Instance Method Summary collapse
-
#initialize(options = {}) ⇒ RestGateway
constructor
A new instance of RestGateway.
Methods included from Logging
add_argument_header, dev, filename, #log_exception, logger, #logger, reset, set_logger, setup
Constructor Details
#initialize(options = {}) ⇒ RestGateway
Returns a new instance of RestGateway.
51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/mb/rest_gateway.rb', line 51 def initialize( = {}) log.debug { "REST Gateway starting..." } = DEFAULT_OPTIONS.merge(.slice(*VALID_OPTIONS)) app = MB::API::Application.new # reel-rack uses Rack standard capitalizations in > 0.0.2 [:Host] = [:host] [:Port] = [:port] log.info { "REST Gateway listening on #{[:host]}:#{[:port]}" } begin super(app, ) rescue Errno::EADDRINUSE log.fatal { "Port #{[:port]} is already in use. Unable to start rest gateway." } end end |
Class Method Details
.instance ⇒ Celluloid::Actor(Gateway)
9 10 11 |
# File 'lib/mb/rest_gateway.rb', line 9 def instance MB::Application[:rest_gateway] or raise Celluloid::DeadActorError, "REST Gateway not running" end |
.start(options = {}) ⇒ Object
Note:
you probably don’t want to manually start the REST Gateway unless you are testing. Start the entire application with MB::Application.run
Start the REST Gateway and add it to the application’s registry.
17 18 19 |
# File 'lib/mb/rest_gateway.rb', line 17 def start( = {}) MB::Application[:rest_gateway] = new() end |
.stop ⇒ Object
Note:
you probably don’t want to manually stop the REST Gateway unless you are testing. Stop the entire application with MB::Application.stop
Stop the currently running REST Gateway
25 26 27 |
# File 'lib/mb/rest_gateway.rb', line 25 def stop instance.shutdown end |