diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-05-27 14:40:55 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-05-27 14:40:55 -0700 |
commit | cfdab77d1fd39a887e9d94342e4e85f915a5b00b (patch) | |
tree | 6a2e75717181bcb7d4d47cd111ac4ad92107075e /actionpack/lib/action_dispatch/routing/route_set.rb | |
parent | babcd7d375bc39b3df5526bde0380e0d6d3d243b (diff) | |
parent | 406b1b64649f48bdd724826a05c06fb78f5378ea (diff) | |
download | rails-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/route_set.rb')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/route_set.rb | 28 |
1 files changed, 10 insertions, 18 deletions
diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 924455bce2..8777a9cd71 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -8,6 +8,7 @@ require 'active_support/core_ext/module/remove_method' require 'active_support/core_ext/array/extract_options' require 'action_controller/metal/exceptions' require 'action_dispatch/http/request' +require 'action_dispatch/routing/endpoint' module ActionDispatch module Routing @@ -20,24 +21,17 @@ module ActionDispatch PARAMETERS_KEY = 'action_dispatch.request.path_parameters' - class Dispatcher #:nodoc: + class Dispatcher < Routing::Endpoint #:nodoc: def initialize(defaults) @defaults = defaults @controller_class_names = ThreadSafe::Cache.new end - def call(env) - params = env[PARAMETERS_KEY] + def dispatcher?; true; end - # If any of the path parameters has an invalid encoding then - # raise since it's likely to trigger errors further on. - params.each do |key, value| - next unless value.respond_to?(:valid_encoding?) - - unless value.valid_encoding? - raise ActionController::BadRequest, "Invalid parameter: #{key} => #{value}" - end - end + def serve(req) + req.check_path_parameters! + params = req.path_parameters prepare_params!(params) @@ -46,7 +40,7 @@ module ActionDispatch return [404, {'X-Cascade' => 'pass'}, []] end - dispatch(controller, params[:action], env) + dispatch(controller, params[:action], req.env) end def prepare_params!(params) @@ -703,12 +697,10 @@ module ActionDispatch end old_params = req.path_parameters req.path_parameters = old_params.merge params - dispatcher = route.app - if dispatcher.is_a?(Mapper::Constraints) && dispatcher.matches?(env) - dispatcher = dispatcher.app - end + app = route.app + if app.matches?(req) && app.dispatcher? + dispatcher = app.app - if dispatcher.is_a?(Dispatcher) if dispatcher.controller(params, false) dispatcher.prepare_params!(params) return params |