Method: Rackup::Handler.require_handler

Defined in:
lib/rackup/handler.rb

.require_handler(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'


103
104
105
106
107
108
# File 'lib/rackup/handler.rb', line 103

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

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