# frozen_string_literal: true module Wayfarer module Middleware class Dispatch extend Base def call(task) controller = task[:controller] task[:return_value] = controller.run_callbacks(:action) do case action = task[:action] when Symbol then controller.public_send(action) when Array handler, method = action task[:action] = method handler.new.call(task) else raise ArgumentError, "invalid action: #{action.inspect}" unless action&.include?(Wayfarer::Handler) task[:action] = nil # TODO: Test action.new.call(task) end end yield if block_given? end end end end