Class: Wayfarer::Middleware::Dispatch

Inherits:
Object
  • Object
show all
Extended by:
Base
Defined in:
lib/wayfarer/middleware/dispatch.rb

Constant Summary

Constants included from Base

Base::API_MODULE

Instance Method Summary collapse

Methods included from Base

api, lazy

Instance Method Details

#call(task) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/wayfarer/middleware/dispatch.rb', line 8

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