diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2014-05-28 16:14:22 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2014-05-28 16:14:22 -0700 |
commit | 3c03e7e2ab65a154bf82cbe697a9bddbecc20897 (patch) | |
tree | f1781890ee61cb1cd0e4b263c32cf99b348035a3 /actionpack | |
parent | ac9a3a9d641a44f43796b342f76c5b342ae82de6 (diff) | |
download | rails-3c03e7e2ab65a154bf82cbe697a9bddbecc20897.tar.gz rails-3c03e7e2ab65a154bf82cbe697a9bddbecc20897.tar.bz2 rails-3c03e7e2ab65a154bf82cbe697a9bddbecc20897.zip |
swtich to returning early if to responds to call
Diffstat (limited to 'actionpack')
-rw-r--r-- | actionpack/lib/action_dispatch/routing/mapper.rb | 67 |
1 files changed, 32 insertions, 35 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb index b8aadff5e6..227ceec90f 100644 --- a/actionpack/lib/action_dispatch/routing/mapper.rb +++ b/actionpack/lib/action_dispatch/routing/mapper.rb @@ -237,47 +237,44 @@ module ActionDispatch end def default_controller_and_action - if to.respond_to?(:call) - { } - else - controller = default_controller - action = default_action - - case to - when Symbol - action = to.to_s - when /#/ - controller, action = to.split('#') - when String - controller = to - end - - if @scope[:module] && !controller.is_a?(Regexp) - if controller =~ %r{\A/} - controller = controller[1..-1] - else - controller = [@scope[:module], controller].compact.join("/").presence - end - end - - hash = {} + hash = {} + return hash if to.respond_to? :call + + controller = default_controller + action = default_action + + case to + when Symbol + action = to.to_s + when /#/ + controller, action = to.split('#') + when String + controller = to + end - if controller.is_a? Regexp - hash[:controller] = controller + if @scope[:module] && !controller.is_a?(Regexp) + if controller =~ %r{\A/} + controller = controller[1..-1] else - check_controller! controller - hash[:controller] = controller.to_s if controller + controller = [@scope[:module], controller].compact.join("/").presence end + end - if action.is_a? Regexp - hash[:action] = action - else - check_action! action - hash[:action] = action.to_s if action - end + if controller.is_a? Regexp + hash[:controller] = controller + else + check_controller! controller + hash[:controller] = controller.to_s if controller + end - hash + if action.is_a? Regexp + hash[:action] = action + else + check_action! action + hash[:action] = action.to_s if action end + + hash end def check_action!(action) |