Module: Rack::Handler

Defined in:
lib/rack/handler.rb,
lib/rack/handler/cgi.rb,
lib/rack/handler/lsws.rb,
lib/rack/handler/scgi.rb,
lib/rack/handler/thin.rb,
lib/rack/handler/mongrel.rb,
lib/rack/handler/webrick.rb,
lib/rack/handler/evented_mongrel.rb,
lib/rack/handler/swiftiplied_mongrel.rb,
lib/rack/handler/fastcgi.rb

Overview

Handlers connect web servers with Rack.

Rack includes Handlers for Mongrel, WEBrick, FastCGI, CGI, SCGI and LiteSpeed.

Handlers usually are activated by calling MyHandler.run(myapp). A second optional hash can be passed to include server-specific configuration.

Defined Under Namespace

Classes: CGI, EventedMongrel, FastCGI, LSWS, Mongrel, SCGI, SwiftipliedMongrel, Thin, WEBrick

Class Method Summary collapse

Class Method Details

.get(server) ⇒ Object



11
12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/rack/handler.rb', line 11

def self.get(server)
  return unless server
  server = server.to_s

  if klass = @handlers[server]
    obj = Object
    klass.split("::").each { |x| obj = obj.const_get(x) }
    obj
  else
    try_require('rack/handler', server)
    const_get(server)
  end
end

.register(server, klass) ⇒ Object



44
45
46
47
# File 'lib/rack/handler.rb', line 44

def self.register(server, klass)
  @handlers ||= {}
  @handlers[server] = klass
end

.try_require(prefix, const_name) ⇒ Object

Transforms server-name constants to their canonical form as filenames, then tries to require them but silences the LoadError if not found

Naming convention:

Foo # => 'foo'
FooBar # => 'foo_bar.rb'
FooBAR # => 'foobar.rb'
FOObar # => 'foobar.rb'
FOOBAR # => 'foobar.rb'
FooBarBaz # => 'foo_bar_baz.rb'


36
37
38
39
40
41
42
# File 'lib/rack/handler.rb', line 36

def self.try_require(prefix, const_name)
  file = const_name.gsub(/^[A-Z]+/) { |pre| pre.downcase }.
    gsub(/[A-Z]+[^A-Z]/, '_\&').downcase

  require(::File.join(prefix, file))
rescue LoadError
end