Class: Shogun::Dispatch
- Inherits:
-
Object
- Object
- Shogun::Dispatch
- Defined in:
- lib/shogun/dispatch.rb,
lib/shogun/dispatch/route.rb,
lib/shogun/dispatch/lookup.rb,
lib/shogun/dispatch/payload.rb,
lib/shogun/dispatch/route/null.rb
Defined Under Namespace
Classes: Lookup, Payload, Route
Constant Summary collapse
- PATH_KEY =
"REQUEST_PATH"
- METHOD_KEY =
"REQUEST_METHOD"
- NO_MATCH =
-> { // }
Instance Method Summary collapse
- #call(state) ⇒ Object
-
#initialize(logger:) {|_self| ... } ⇒ Dispatch
constructor
A new instance of Dispatch.
- #push(route:) ⇒ Object
Constructor Details
#initialize(logger:) {|_self| ... } ⇒ Dispatch
Returns a new instance of Dispatch.
23 24 25 26 27 |
# File 'lib/shogun/dispatch.rb', line 23 def initialize(logger:) @routes = {} @logger = logger yield(self) end |
Instance Method Details
#call(state) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 |
# 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:) ⇒ Object
51 52 53 |
# File 'lib/shogun/dispatch.rb', line 51 def push(route:) routes[route.as_key] = route end |