class Rack::Builder

def self.parse_file(path)

# assumes MyApp constant contains Rack application
# process's current directory. After requiring,
# requires ./my_app.rb, which should be in the
Rack::Builder.parse_file('./my_app.rb')

# contains Rack application
# load path. After requiring, assumes App constant
# requires app.rb, which can be anywhere in Ruby's
Rack::Builder.parse_file('app.rb')

# Rack application built using Rack::Builder.new
Rack::Builder.parse_file('config.ru')

Examples:

to guess which constant will be the Rack application to run.
required and Rack will use the basename of the file
If the config file does not end in +.ru+, it is

specified inside a Rack::Builder block.
rackup file and the contents will be treated as if
If the config file ends in +.ru+, it is treated as a

Parse the given config file to get a Rack application.
def self.parse_file(path)
  if path.end_with?('.ru')
    return self.load_file(path)
  else
    require path
    return Object.const_get(::File.basename(path, '.rb').split('_').map(&:capitalize).join(''))
  end
end