Class Index [+]

Quicksearch

Rack::Handler

Handlers connect web servers with Rack.

Rack includes Handlers for Thin, 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.

Public Class Methods

default(options = {}) click to toggle source
    # File lib/rack/handler.rb, line 29
29:     def self.default(options = {})
30:       # Guess.
31:       if ENV.include?("PHP_FCGI_CHILDREN")
32:         # We already speak FastCGI
33:         options.delete :File
34:         options.delete :Port
35: 
36:         Rack::Handler::FastCGI
37:       elsif ENV.include?("REQUEST_METHOD")
38:         Rack::Handler::CGI
39:       else
40:         begin
41:           Rack::Handler::Thin
42:         rescue LoadError
43:           Rack::Handler::WEBrick
44:         end
45:       end
46:     end
get(server) click to toggle source
    # File lib/rack/handler.rb, line 11
11:     def self.get(server)
12:       return unless server
13:       server = server.to_s
14: 
15:       unless @handlers.include? server
16:         load_error = try_require('rack/handler', server)
17:       end
18: 
19:       if klass = @handlers[server]
20:         klass.split("::").inject(Object) { |o, x| o.const_get(x) }
21:       else
22:         const_get(server)
23:       end
24: 
25:     rescue NameError => name_error
26:       raise load_error || name_error
27:     end
register(server, klass) click to toggle source
    # File lib/rack/handler.rb, line 69
69:     def self.register(server, klass)
70:       @handlers ||= {}
71:       @handlers[server.to_s] = klass.to_s
72:     end
try_require(prefix, const_name) click to toggle source

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'
    # File lib/rack/handler.rb, line 59
59:     def self.try_require(prefix, const_name)
60:       file = const_name.gsub(/^[A-Z]+/) { |pre| pre.downcase }.
61:         gsub(/[A-Z]+[^A-Z]/, '_\&').downcase
62: 
63:       require(::File.join(prefix, file))
64:       nil
65:     rescue LoadError => error
66:       error
67:     end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.