Skip to content

Instantly share code, notes, and snippets.

@artemave
Created November 10, 2011 12:19
Show Gist options
  • Save artemave/1354726 to your computer and use it in GitHub Desktop.
Save artemave/1354726 to your computer and use it in GitHub Desktop.
sinatra handler options
module Sinatra
class Base
class << self
def run!(options={})
set options
handler = detect_rack_handler
handler_name = handler.name.gsub(/.*::/, '')
# handler specific options use the lower case handler name as hash key, if present
handler_opts = begin
send(handler_name.downcase)
rescue NoMethodError
{}
end
puts "== Sinatra/#{Sinatra::VERSION} has taken the stage " +
"on #{port} for #{environment} with backup from #{handler_name}" unless handler_name =~/cgi/i
handler.run self, handler_opts.merge(:Host => bind, :Port => port) do |server|
[:INT, :TERM].each { |sig| trap(sig) { quit!(server, handler_name) } }
set :running, true
end
rescue Errno::EADDRINUSE => e
puts "== Someone is already performing on port #{port}!"
end
end
end
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment