提交 67b2841f 编写于 作者: A Aaron Patterson

adding a direct dispatch method to controller classes

This saves a lambda and request allocation on each request.
上级 a26033b4
......@@ -259,5 +259,15 @@ def self.action(name)
lambda { |env| new.dispatch(name, ActionDispatch::Request.new(env)) }
end
end
# Direct dispatch to the controller. Instantiates the controller, then
# executes the action named +name+.
def self.dispatch(name, req)
if middleware_stack.any?
middleware_stack.build(name) { |env| new.dispatch(name, req) }.call req.env
else
new.dispatch(name, req)
end
end
end
end
......@@ -44,7 +44,7 @@ def controller(req)
end
def dispatch(controller, action, req)
controller.action(action).call(req.env)
controller.dispatch(action, req)
end
end
......
......@@ -124,16 +124,10 @@ class DeadEndRoutes < ActionDispatch::Routing::RouteSet
class NullController
def initialize(controller_name)
@controller = controller_name
@action = nil
end
def action(action_name)
@action = action_name
self
end
def call(env)
[200, {'Content-Type' => 'text/html'}, ["#{@controller}##{@action}"]]
def dispatch(action, req)
[200, {'Content-Type' => 'text/html'}, ["#{@controller}##{action}"]]
end
end
......
Markdown is supported
0% .
You are about to add 0 people to the discussion. Proceed with caution.
先完成此消息的编辑!
想要评论请 注册