Rack::Builder implements a small DSL to iteratively construct Rack applications.
Example:
app = Rack::Builder.new {
use Rack::CommonLogger
use Rack::ShowExceptions
map "/lobster" do
use Rack::Lint
run Rack::Lobster.new
end
}
Or
app = Rack::Builder.app do
use Rack::CommonLogger
lambda { |env| [200, {'Content-Type' => 'text/plain'}, 'OK'] }
end
use adds a middleware to the stack, run dispatches to an application. You can use map to construct a Rack::URLMap in a convenient way.
(Not documented)
# File lib/rack/builder.rb, line 49
49: def self.app(&block)
50: self.new(&block).to_app
51: end
(Not documented)
# File lib/rack/builder.rb, line 44
44: def initialize(&block)
45: @ins = []
46: instance_eval(&block) if block_given?
47: end
(Not documented)
# File lib/rack/builder.rb, line 27
27: def self.parse_file(config, opts = Server::Options.new)
28: options = {}
29: if config =~ /\.ru$/
30: cfgfile = ::File.read(config)
31: if cfgfile[/^#\\(.*)/] && opts
32: options = opts.parse! $1.split(/\s+/)
33: end
34: cfgfile.sub!(/^__END__\n.*/, '')
35: app = eval "Rack::Builder.new {( " + cfgfile + "\n )}.to_app",
36: TOPLEVEL_BINDING, config
37: else
38: require config
39: app = Object.const_get(::File.basename(config, '.rb').capitalize)
40: end
41: return app, options
42: end
(Not documented)
# File lib/rack/builder.rb, line 76
76: def call(env)
77: to_app.call(env)
78: end
(Not documented)
# File lib/rack/builder.rb, line 61
61: def map(path, &block)
62: if @ins.last.kind_of? Hash
63: @ins.last[path] = self.class.new(&block).to_app
64: else
65: @ins << {}
66: map(path, &block)
67: end
68: end
(Not documented)
# File lib/rack/builder.rb, line 57
57: def run(app)
58: @ins << app #lambda { |nothing| app }
59: end
Disabled; run with --debug to generate this.
Generated with the Darkfish Rdoc Generator 1.1.6.