diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2015-06-08 17:18:06 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2015-06-08 17:18:32 -0700 |
commit | 8037d7eacd14376d2c093d27f5b7d18fed085916 (patch) | |
tree | 0f13db0b57581d3bb9f4ab7095cbe3ad30367228 /actionpack/lib/action_dispatch | |
parent | ec69a45f5bb49c096f460a6bbe85d9d8890488b5 (diff) | |
download | rails-8037d7eacd14376d2c093d27f5b7d18fed085916.tar.gz rails-8037d7eacd14376d2c093d27f5b7d18fed085916.tar.bz2 rails-8037d7eacd14376d2c093d27f5b7d18fed085916.zip |
extract required_defaults from the conditions hash before constructing the route
this way we can remove the strange "respond_to?" conditional in the
`matches?` loop
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r-- | actionpack/lib/action_dispatch/journey/route.rb | 7 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/journey/routes.rb | 4 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/routing/route_set.rb | 5 |
3 files changed, 8 insertions, 8 deletions
diff --git a/actionpack/lib/action_dispatch/journey/route.rb b/actionpack/lib/action_dispatch/journey/route.rb index 4698ff8cc7..cbc985640a 100644 --- a/actionpack/lib/action_dispatch/journey/route.rb +++ b/actionpack/lib/action_dispatch/journey/route.rb @@ -11,7 +11,7 @@ module ActionDispatch ## # +path+ is a path constraint. # +constraints+ is a hash of constraints to be applied to this route. - def initialize(name, app, path, constraints, defaults = {}) + def initialize(name, app, path, constraints, required_defaults, defaults) @name = name @app = app @path = path @@ -19,6 +19,7 @@ module ActionDispatch @constraints = constraints @defaults = defaults @required_defaults = nil + @_required_defaults = required_defaults || [] @required_parts = nil @parts = nil @decorated_ast = nil @@ -73,7 +74,7 @@ module ActionDispatch end def required_default?(key) - (constraints[:required_defaults] || []).include?(key) + @_required_defaults.include?(key) end def required_defaults @@ -92,8 +93,6 @@ module ActionDispatch def matches?(request) constraints.all? do |method, value| - next true unless request.respond_to?(method) - case value when Regexp, String value === request.send(method).to_s diff --git a/actionpack/lib/action_dispatch/journey/routes.rb b/actionpack/lib/action_dispatch/journey/routes.rb index 6325dfa3dd..5990964b57 100644 --- a/actionpack/lib/action_dispatch/journey/routes.rb +++ b/actionpack/lib/action_dispatch/journey/routes.rb @@ -63,8 +63,8 @@ module ActionDispatch end # Add a route to the routing table. - def add_route(app, path, conditions, defaults, name = nil) - route = Route.new(name, app, path, conditions, defaults) + def add_route(app, path, conditions, required_defaults, defaults, name = nil) + route = Route.new(name, app, path, conditions, required_defaults, defaults) route.precedence = routes.length routes << route diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index d0d8ded515..1e950d13f8 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -511,10 +511,11 @@ module ActionDispatch path = conditions.delete :path_info ast = conditions.delete :parsed_path_info + required_defaults = conditions.delete :required_defaults path = build_path(path, ast, requirements, anchor) conditions = build_conditions(conditions, path.names.map(&:to_sym)) - route = @set.add_route(app, path, conditions, defaults, name) + route = @set.add_route(app, path, conditions, required_defaults, defaults, name) named_routes[name] = route if name route end @@ -563,7 +564,7 @@ module ActionDispatch end conditions.keep_if do |k, _| - k == :action || k == :controller || k == :required_defaults || + k == :action || k == :controller || request_class.public_method_defined?(k) || path_values.include?(k) end end |