aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/routing/mapper.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-05-27 14:40:55 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2014-05-27 14:40:55 -0700
commitcfdab77d1fd39a887e9d94342e4e85f915a5b00b (patch)
tree6a2e75717181bcb7d4d47cd111ac4ad92107075e /actionpack/lib/action_dispatch/routing/mapper.rb
parentbabcd7d375bc39b3df5526bde0380e0d6d3d243b (diff)
parent406b1b64649f48bdd724826a05c06fb78f5378ea (diff)
downloadrails-cfdab77d1fd39a887e9d94342e4e85f915a5b00b.tar.gz
rails-cfdab77d1fd39a887e9d94342e4e85f915a5b00b.tar.bz2
rails-cfdab77d1fd39a887e9d94342e4e85f915a5b00b.zip
Merge branch 'constraints'
* constraints: rm reset_parameters because we automatically do it from 9ca4839a move path_parameter encoding check to the request object dispatcher doesn't need `call` anymore call `serve` with the request on dispatchers constraints class does not need the request class anymore give all endpoints a superclass skip the build business if the stack is empty stop hardcoding path_parameters and get it from the request we do not need to cache rack_app a redirect is not a dispatcher by definition, so eliminate test push is_a check up to where the Constraints object is allocated pass the request object to the application pass a request to `matches?` so we can avoid creating excess requests nothing is passed to `rack_app` anymore, so rm the params one fewer is_a check Constraints#app should never return another Constraints object, so switch to if statement eliminate dispatcher is_a checks push is_a?(Dispatcher) check in to one place Always construct route objects with Constraint objects Conflicts: actionpack/lib/action_controller/metal.rb
Diffstat (limited to 'actionpack/lib/action_dispatch/routing/mapper.rb')
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb43
1 files changed, 26 insertions, 17 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index b33c5e0dfd..84a08770f5 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -6,6 +6,7 @@ require 'active_support/core_ext/array/extract_options'
require 'active_support/core_ext/module/remove_method'
require 'active_support/inflector'
require 'action_dispatch/routing/redirection'
+require 'action_dispatch/routing/endpoint'
module ActionDispatch
module Routing
@@ -15,35 +16,41 @@ module ActionDispatch
:controller, :action, :path_names, :constraints,
:shallow, :blocks, :defaults, :options]
- class Constraints #:nodoc:
+ class Constraints < Endpoint #:nodoc:
attr_reader :app, :constraints
- def initialize(app, constraints, request)
+ def initialize(app, constraints, dispatcher_p)
# Unwrap Constraints objects. I don't actually think it's possible
# to pass a Constraints object to this constructor, but there were
# multiple places that kept testing children of this object. I
# *think* they were just being defensive, but I have no idea.
- while app.is_a?(self.class)
+ if app.is_a?(self.class)
constraints += app.constraints
app = app.app
end
- @app, @constraints, @request = app, constraints, request
+ @dispatcher = dispatcher_p
+
+ @app, @constraints, = app, constraints
end
- def matches?(env)
- req = @request.new(env)
+ def dispatcher?; @dispatcher; end
+ 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'}, [] ]
+ def serve(req)
+ return [ 404, {'X-Cascade' => 'pass'}, [] ] unless matches?(req)
+
+ if dispatcher?
+ @app.serve req
+ else
+ @app.call req.env
+ end
end
private
@@ -216,10 +223,16 @@ module ActionDispatch
end
def app
- if blocks.any?
- Constraints.new(endpoint, blocks, @set.request_class)
+ return to if Redirect === to
+
+ if to.respond_to?(:call)
+ Constraints.new(to, blocks, false)
else
- endpoint
+ if blocks.any?
+ Constraints.new(dispatcher, blocks, true)
+ else
+ dispatcher
+ end
end
end
@@ -306,10 +319,6 @@ module ActionDispatch
Journey::Router::Strexp.compile(path, requirements, SEPARATORS)
end
- def endpoint
- to.respond_to?(:call) ? to : dispatcher
- end
-
def dispatcher
Routing::RouteSet::Dispatcher.new(defaults)
end