Module: Sinatra::MoreServer::Unicorn

Defined in:
lib/sinatra/more_server/unicorn.rb

Overview

Rack Handler to use Unicorn for Sinatra::Base.run!

Class Method Summary collapse

Class Method Details

.run(app, options = {}) {|server| ... } ⇒ Object

Yields:

  • (server)


10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
# File 'lib/sinatra/more_server/unicorn.rb', line 10

def self.run(app, options={})
  app = Rack::Builder.new do
    # TODO: env dependend stuff.
    use Rack::CommonLogger, $stderr
    use Rack::ShowExceptions
    run app
  end.to_app
  options[:Backend] ||= ::Unicorn
  options[:Host] ||= ::Unicorn::Const::DEFAULT_HOST
  options[:Port] ||= ::Unicorn::Const::DEFAULT_PORT
  options[:listeners] = ["#{options.delete :Host}:#{options.delete :Port}"]
  server = options.delete(:Backend)::HttpServer.new app, options
  yield server if block_given?
  server.start.join
end