aboutsummaryrefslogtreecommitdiffstats
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-05-28 16:59:32 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2014-05-28 16:59:32 -0700
commit89bf31ee565a0f5b1d7138deaa1873223ef22da2 (patch)
tree351274b40d13983e999abc19e8d3bf16175785c8
parent78deb7f1b82f2b8fbe9aee4c0aa7f7557f4ff533 (diff)
downloadrails-89bf31ee565a0f5b1d7138deaa1873223ef22da2.tar.gz
rails-89bf31ee565a0f5b1d7138deaa1873223ef22da2.tar.bz2
rails-89bf31ee565a0f5b1d7138deaa1873223ef22da2.zip
move nil check to a method that yields to a block if the value is not nil
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb33
1 files changed, 16 insertions, 17 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index d7e0d932fb..58e8ac0201 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -237,8 +237,7 @@ module ActionDispatch
end
def default_controller_and_action
- hash = {}
- return hash if to.respond_to? :call
+ return {} if to.respond_to? :call
controller, action = get_controller_and_action(
default_controller,
@@ -247,24 +246,28 @@ module ActionDispatch
@scope[:module]
)
- if controller
- hash[:controller] = translate_controller controller
- else
- unless segment_keys.include?(:controller)
- message = "Missing :controller key on routes definition, please check your routes."
- raise ArgumentError, message
+ hash = check_part(:controller, controller, {}) do
+ translate_controller controller
+ end
+
+ check_part(:action, action, hash) do
+ if Regexp === action
+ action
+ else
+ action.to_s
end
end
+ end
- if action
- hash[:action] = translate_action action
+ def check_part(name, part, hash)
+ if part
+ hash[name] = yield
else
- unless segment_keys.include?(:action)
- message = "Missing :action key on routes definition, please check your routes."
+ unless segment_keys.include?(name)
+ message = "Missing :#{name} key on routes definition, please check your routes."
raise ArgumentError, message
end
end
-
hash
end
@@ -288,10 +291,6 @@ module ActionDispatch
[controller, action]
end
- def translate_action(action)
- Regexp === action ? action : action.to_s
- end
-
def translate_controller(controller)
return controller if Regexp === controller
return controller.to_s if controller =~ /\A[a-z_0-9][a-z_0-9\/]*\z/