提交 89bf31ee 编写于 作者: A Aaron Patterson

move nil check to a method that yields to a block if the value is not nil

上级 78deb7f1
...@@ -237,8 +237,7 @@ def app ...@@ -237,8 +237,7 @@ def app
end end
def default_controller_and_action def default_controller_and_action
hash = {} return {} if to.respond_to? :call
return hash if to.respond_to? :call
controller, action = get_controller_and_action( controller, action = get_controller_and_action(
default_controller, default_controller,
...@@ -247,24 +246,28 @@ def default_controller_and_action ...@@ -247,24 +246,28 @@ def default_controller_and_action
@scope[:module] @scope[:module]
) )
if controller hash = check_part(:controller, controller, {}) do
hash[:controller] = translate_controller controller translate_controller controller
else end
unless segment_keys.include?(:controller)
message = "Missing :controller key on routes definition, please check your routes." check_part(:action, action, hash) do
raise ArgumentError, message if Regexp === action
action
else
action.to_s
end end
end end
end
if action def check_part(name, part, hash)
hash[:action] = translate_action action if part
hash[name] = yield
else else
unless segment_keys.include?(:action) unless segment_keys.include?(name)
message = "Missing :action key on routes definition, please check your routes." message = "Missing :#{name} key on routes definition, please check your routes."
raise ArgumentError, message raise ArgumentError, message
end end
end end
hash hash
end end
...@@ -288,10 +291,6 @@ def get_controller_and_action(controller, action, to, modyoule) ...@@ -288,10 +291,6 @@ def get_controller_and_action(controller, action, to, modyoule)
[controller, action] [controller, action]
end end
def translate_action(action)
Regexp === action ? action : action.to_s
end
def translate_controller(controller) def translate_controller(controller)
return controller if Regexp === controller return controller if Regexp === controller
return controller.to_s if controller =~ /\A[a-z_0-9][a-z_0-9\/]*\z/ return controller.to_s if controller =~ /\A[a-z_0-9][a-z_0-9\/]*\z/
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册