vendor/rack/lib/rack/builder.rb in relevance-castronaut-0.5.4 vs vendor/rack/lib/rack/builder.rb in relevance-castronaut-0.6.0

- old
+ new

@@ -11,19 +11,30 @@ # 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. class Builder def initialize(&block) @ins = [] instance_eval(&block) if block_given? end + def self.app(&block) + self.new(&block).to_app + end + def use(middleware, *args, &block) @ins << if block_given? lambda { |app| middleware.new(app, *args, &block) } else lambda { |app| middleware.new(app, *args) } @@ -34,10 +45,10 @@ @ins << app #lambda { |nothing| app } end def map(path, &block) if @ins.last.kind_of? Hash - @ins.last[path] = Rack::Builder.new(&block).to_app + @ins.last[path] = self.class.new(&block).to_app else @ins << {} map(path, &block) end end