pass a request to matches? so we can avoid creating excess requests

This commit is contained in:
Aaron Patterson 2014-05-25 14:11:34 -07:00
parent cff0d15e4b
commit 62c013d7b1
2 changed files with 6 additions and 7 deletions

@ -35,19 +35,18 @@ def initialize(app, constraints, request, dispatcher_p)
def dispatcher?; @dispatcher; end
def matches?(env)
req = @request.new(env)
def matches?(req)
@constraints.all? do |constraint|
(constraint.respond_to?(:matches?) && constraint.matches?(req)) ||
(constraint.respond_to?(:call) && constraint.call(*constraint_args(constraint, req)))
end
ensure
req.reset_parameters
end
def call(env)
matches?(env) ? @app.call(env) : [ 404, {'X-Cascade' => 'pass'}, [] ]
req = @request.new(env)
matches?(req) ? @app.call(env) : [ 404, {'X-Cascade' => 'pass'}, [] ]
ensure
req.reset_parameters
end
private

@ -704,7 +704,7 @@ def recognize_path(path, environment = {})
old_params = req.path_parameters
req.path_parameters = old_params.merge params
app = route.app
if app.matches?(env) && app.dispatcher?
if app.matches?(req) && app.dispatcher?
dispatcher = app.app
if dispatcher.controller(params, false)