aboutsummaryrefslogtreecommitdiffstats
path: root/actionpack/lib/action_dispatch/routing/mapper.rb
diff options
context:
space:
mode:
authorAaron Patterson <aaron.patterson@gmail.com>2014-05-28 15:33:32 -0700
committerAaron Patterson <aaron.patterson@gmail.com>2014-05-28 15:33:32 -0700
commitddda5e70f79288f03a873cc8b4dbc6c086f4ad82 (patch)
treeb1c612c587f4513eb87b8def024444a9069e8d91 /actionpack/lib/action_dispatch/routing/mapper.rb
parent1ad50aa37939da41714409bf249dcb208dba3c75 (diff)
downloadrails-ddda5e70f79288f03a873cc8b4dbc6c086f4ad82.tar.gz
rails-ddda5e70f79288f03a873cc8b4dbc6c086f4ad82.tar.bz2
rails-ddda5e70f79288f03a873cc8b4dbc6c086f4ad82.zip
extract controller checks to methods
Diffstat (limited to 'actionpack/lib/action_dispatch/routing/mapper.rb')
-rw-r--r--actionpack/lib/action_dispatch/routing/mapper.rb45
1 files changed, 26 insertions, 19 deletions
diff --git a/actionpack/lib/action_dispatch/routing/mapper.rb b/actionpack/lib/action_dispatch/routing/mapper.rb
index 68f9225a45..e0b725c8f2 100644
--- a/actionpack/lib/action_dispatch/routing/mapper.rb
+++ b/actionpack/lib/action_dispatch/routing/mapper.rb
@@ -260,28 +260,11 @@ module ActionDispatch
end
end
- if controller.is_a?(String) && controller =~ %r{\A/}
- raise ArgumentError, "controller name should not start with a slash"
- end
-
controller = controller.to_s unless controller.is_a?(Regexp)
action = action.to_s unless action.is_a?(Regexp)
- if controller.blank? && segment_keys.exclude?(:controller)
- message = "Missing :controller key on routes definition, please check your routes."
- raise ArgumentError, message
- end
-
- if action.blank? && segment_keys.exclude?(:action)
- message = "Missing :action key on routes definition, please check your routes."
- raise ArgumentError, message
- end
-
- if controller.is_a?(String) && controller !~ /\A[a-z_0-9\/]*\z/
- message = "'#{controller}' is not a supported controller name. This can lead to potential routing problems."
- message << " See http://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use"
- raise ArgumentError, message
- end
+ check_action! action
+ check_controller! controller
hash = {}
hash[:controller] = controller unless controller.blank?
@@ -290,6 +273,30 @@ module ActionDispatch
end
end
+ def check_action!(action)
+ if action.blank? && segment_keys.exclude?(:action)
+ message = "Missing :action key on routes definition, please check your routes."
+ raise ArgumentError, message
+ end
+ end
+
+ def check_controller!(controller)
+ if controller.is_a?(String) && controller =~ %r{\A/}
+ raise ArgumentError, "controller name should not start with a slash"
+ end
+
+ if controller.blank? && segment_keys.exclude?(:controller)
+ message = "Missing :controller key on routes definition, please check your routes."
+ raise ArgumentError, message
+ end
+
+ if controller.is_a?(String) && controller !~ /\A[a-z_0-9\/]*\z/
+ message = "'#{controller}' is not a supported controller name. This can lead to potential routing problems."
+ message << " See http://guides.rubyonrails.org/routing.html#specifying-a-controller-to-use"
+ raise ArgumentError, message
+ end
+ end
+
def blocks
if options[:constraints].present? && !options[:constraints].is_a?(Hash)
[options[:constraints]]