From dc1b937db780155089fce522f03d340e62f5df36 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sat, 8 Aug 2015 16:34:34 -0700 Subject: Remove `defaults` hash from `Dispatcher` `Dispatcher` doesn't need to hold on to the defaults hash. It only used the hash to determine whether or not it should raise an exception if there is a name error. We can pass that in further up the stack and alleviate Dispatcher from knowing about that hash. --- actionpack/lib/action_dispatch/routing/mapper.rb | 4 ++-- actionpack/lib/action_dispatch/routing/route_set.rb | 14 +++++++------- 2 files changed, 9 insertions(+), 9 deletions(-) (limited to 'actionpack/lib') diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index 7513c62128..d5f641a88a 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -242,9 +242,9 @@ module ActionDispatch if to.respond_to?(:call) Constraints.new(to, blocks, Constraints::CALL) elsif blocks.any? - Constraints.new(dispatcher(defaults), blocks, Constraints::SERVE) + Constraints.new(dispatcher(defaults.key?(:controller)), blocks, Constraints::SERVE) else - dispatcher(defaults) + dispatcher(defaults.key?(:controller)) end end diff --git a/actionpack/lib/action_dispatch/routing/route_set.rb b/actionpack/lib/action_dispatch/routing/route_set.rb index 1742daf1de..cc86890c0a 100644 --- a/actionpack/lib/action_dispatch/routing/route_set.rb +++ b/actionpack/lib/action_dispatch/routing/route_set.rb @@ -21,8 +21,8 @@ module ActionDispatch alias inspect to_s class Dispatcher < Routing::Endpoint - def initialize(defaults) - @defaults = defaults + def initialize(raise_on_name_error) + @raise_on_name_error = raise_on_name_error @controller_class_names = ThreadSafe::Cache.new end @@ -35,7 +35,7 @@ module ActionDispatch prepare_params!(params) # Just raise undefined constant errors if a controller was specified as default. - unless controller = controller(params, @defaults.key?(:controller)) + unless controller = controller(params, @raise_on_name_error) return [404, {'X-Cascade' => 'pass'}, []] end @@ -53,13 +53,13 @@ module ActionDispatch # segment, as in :controller(/:action), we should simply return nil and # delegate the control back to Rack cascade. Besides, if this is not a default # controller, it means we should respect the @scope[:module] parameter. - def controller(params, default_controller=true) + def controller(params, raise_on_name_error=true) if params && params.key?(:controller) controller_param = params[:controller] controller_reference(controller_param) end rescue NameError => e - raise ActionController::RoutingError, e.message, e.backtrace if default_controller + raise ActionController::RoutingError, e.message, e.backtrace if raise_on_name_error end protected @@ -418,8 +418,8 @@ module ActionDispatch @prepend.each { |blk| eval_block(blk) } end - def dispatcher(defaults) - dispatcher_class.new(defaults) + def dispatcher(raise_on_name_error) + dispatcher_class.new(raise_on_name_error) end module MountedHelpers -- cgit v1.2.3