Permalink
Browse files

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

  • Loading branch information...
tenderlove committed May 25, 2014
1 parent cff0d15 commit 62c013d7b18d726d0ce10c3e7a1208d5e0e7fadf
@@ -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)

0 comments on commit 62c013d

Please sign in to comment.