# frozen_string_literal: true module Wayfarer module Middleware module Controller extend ActiveSupport::Concern included do class_attribute :chain, default: Chain.empty, instance_accessor: false, instance_predicate: false attr_accessor :task include Wayfarer::Callbacks end class_methods do def use(middleware) chain.push(middleware.lazy) api(middleware) end def api(middleware) include middleware.api end end def call(task) self.task = task task[:job] ||= self task[:controller] = self self.class.chain.call(task) do yield if block_given? end task[:return_value] end end end end