class Shogun::Dispatch

Constants

METHOD_KEY
NO_MATCH
PATH_KEY

Attributes

lookup[R]
payload[R]
route[R]
routes[R]

Public Class Methods

new(logger:) { |self| ... } click to toggle source
# File lib/shogun/dispatch.rb, line 23
def initialize(logger:)
  @routes = {}
  @logger = logger
  yield(self)
end

Public Instance Methods

call(state) click to toggle source
# File lib/shogun/dispatch.rb, line 29
def call(state)
  @state = state

  lookup = Lookup.new(routes: routes, verb: state[METHOD_KEY], path: state[PATH_KEY])

  payload = Payload.new(state: state, lookup: lookup)

  route = lookup.to_route

  control = route.control.new(payload: payload)

  @logger.debug(self.class) do
    "Request `#{lookup.request}` handled by `#{route.control}`"
  end

  control.to_a.tap do |response|
    @logger.debug(self.class) do
      "Response `#{response[0]}` with `#{response[2]}`"
    end
  end
end
push(route:) click to toggle source
# File lib/shogun/dispatch.rb, line 51
def push(route:)
  routes[route.as_key] = route
end

Private Instance Methods

body() click to toggle source
# File lib/shogun/dispatch.rb, line 71
        def body
  @body
end
headers() click to toggle source
# File lib/shogun/dispatch.rb, line 63
        def headers
  @headers
end
stack() click to toggle source
# File lib/shogun/dispatch.rb, line 55
        def stack
  @stack
end
state() click to toggle source
# File lib/shogun/dispatch.rb, line 59
        def state
  @state
end
status() click to toggle source
# File lib/shogun/dispatch.rb, line 67
        def status
  @status
end