adding a direct dispatch method to controller classes
This saves a lambda and request allocation on each request.
This commit is contained in:
parent
a26033b4a6
commit
67b2841fbe
@ -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
|
||||
|
||||
|
Loading…
Reference in New Issue
Block a user