diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2015-08-08 16:34:34 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2015-08-08 16:34:34 -0700 |
commit | dc1b937db780155089fce522f03d340e62f5df36 (patch) | |
tree | bb05915ffe93f9a837bf556c7b1929a0dee27023 /actionpack | |
parent | 175e92c9ac674536ad6c54937b54ef2e77217f08 (diff) | |
download | rails-dc1b937db780155089fce522f03d340e62f5df36.tar.gz rails-dc1b937db780155089fce522f03d340e62f5df36.tar.bz2 rails-dc1b937db780155089fce522f03d340e62f5df36.zip |
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.
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 4 | ||||
-rw-r--r-- | actionpack/lib/action_dispatch/routing/route_set.rb | 14 |
2 files changed, 9 insertions, 9 deletions
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 |