From bb1003080259b3c6cb974e5c9d55a561a9530cbb Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Mon, 17 Aug 2015 16:39:26 -0700 Subject: split the verb regex from the constraints hash verb matching is very common (all routes besides rack app endpoints require one). We will extract verb matching for now, and use a more efficient method of matching (then regexp) later --- actionpack/lib/action_dispatch/journey/route.rb | 23 +++++++++++++++++------ 1 file changed, 17 insertions(+), 6 deletions(-) (limited to 'actionpack/lib/action_dispatch/journey/route.rb') diff --git a/actionpack/lib/action_dispatch/journey/route.rb b/actionpack/lib/action_dispatch/journey/route.rb index d44c3d31d7..fa69ba776a 100644 --- a/actionpack/lib/action_dispatch/journey/route.rb +++ b/actionpack/lib/action_dispatch/journey/route.rb @@ -8,18 +8,21 @@ module ActionDispatch attr_accessor :precedence + ANY = // def self.build(name, app, path, constraints, required_defaults, defaults) - new name, app, path, constraints, required_defaults, defaults + request_method_match = constraints.delete(:request_method) || ANY + new name, app, path, constraints, required_defaults, defaults, request_method_match end ## # +path+ is a path constraint. # +constraints+ is a hash of constraints to be applied to this route. - def initialize(name, app, path, constraints, required_defaults, defaults) + def initialize(name, app, path, constraints, required_defaults, defaults, request_method_match) @name = name @app = app @path = path + @request_method_match = request_method_match @constraints = constraints @defaults = defaults @required_defaults = nil @@ -96,7 +99,8 @@ module ActionDispatch end def matches?(request) - constraints.all? do |method, value| + match_verb(request) && + constraints.all? { |method, value| case value when Regexp, String value === request.send(method).to_s @@ -109,7 +113,7 @@ module ActionDispatch else value === request.send(method) end - end + } end def ip @@ -117,11 +121,18 @@ module ActionDispatch end def requires_matching_verb? - constraints[:request_method] + @request_method_match != ANY end def verb - constraints[:request_method] || // + @request_method_match + end + + private + + def match_verb(request) + return true unless requires_matching_verb? + verb === request.request_method end end end -- cgit v1.2.3