Permalink
Browse files

Simplify the Sinatra.server method

Removes the case from Sinatra.server, since we can rely on eval anyway, if we properly convert the handler name.
Also, eval might be evil, but the non-eval version is longer, unglier, and harder to understand.
  • Loading branch information...
1 parent b734509 commit 7526dacf33d4411d7f0e98bceeadc91b46dc56bb @cypher cypher committed May 20, 2008
Showing with 4 additions and 17 deletions.
  1. +4 −17 lib/sinatra.rb
View
21 lib/sinatra.rb
@@ -117,23 +117,10 @@ def env
alias :build_application :application
def server
- @server ||= case options.server
- when "mongrel"
- Rack::Handler::Mongrel
- when "webrick"
- Rack::Handler::WEBrick
- when "cgi"
- Rack::Handler::CGI
- when "fastcgi"
- Rack::Handler::FastCGI
- else
- if defined?(Rack::Handler::Thin)
- Rack::Handler::Thin
- else
- options.server ||= "mongrel"
- eval("Rack::Handler::#{options.server.capitalize}")
- end
- end
+ options.server ||= defined?(Rack::Handler::Thin) ? "thin" : "mongrel"
+ # Convert the server into the actual handler name
+ handler = options.server.capitalize.sub(/cgi$/, 'CGI')
+ @server ||= eval("Rack::Handler::#{handler}")
end
def run

0 comments on commit 7526dac

Please sign in to comment.