diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2015-08-17 16:39:26 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2015-08-17 16:39:26 -0700 |
commit | bb1003080259b3c6cb974e5c9d55a561a9530cbb (patch) | |
tree | 4885ec0b5a61932b77cfccd4a7146f5b1a352fdd /actionpack | |
parent | 23cfdd4b71e4284e3efb29a37b2260e2ec77ddc9 (diff) | |
download | rails-bb1003080259b3c6cb974e5c9d55a561a9530cbb.tar.gz rails-bb1003080259b3c6cb974e5c9d55a561a9530cbb.tar.bz2 rails-bb1003080259b3c6cb974e5c9d55a561a9530cbb.zip |
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
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_dispatch/journey/route.rb | 23 |
1 files changed, 17 insertions, 6 deletions
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 |