Class: Granite::Dispatcher
- Inherits:
-
Object
- Object
- Granite::Dispatcher
- Extended by:
- Memoist
- Defined in:
- lib/granite/dispatcher.rb
Instance Method Summary collapse
- #call ⇒ Object
- #constraints ⇒ Object
- #controller(params, *_args) ⇒ Object
- #prepare_params!(params, *_args) ⇒ Object
-
#reset! ⇒ Object
Make dispatcher object pristine, clean memoist cache.
- #serve(req) ⇒ Object
Instance Method Details
#call ⇒ Object
12 13 14 15 16 |
# File 'lib/granite/dispatcher.rb', line 12 def call(*) # Pretend to be a Rack app, however we are still dispatcher, so this method should never be called # see lib/granite/routing/mapping.rb for more info. fail 'Dispatcher can\'t be used as a Rack app.' end |
#constraints ⇒ Object
23 24 25 |
# File 'lib/granite/dispatcher.rb', line 23 def constraints [->(req) { detect_controller_class_and_action_name(req).all?(&:present?) }] end |
#controller(params, *_args) ⇒ Object
27 28 29 |
# File 'lib/granite/dispatcher.rb', line 27 def controller(params, *_args) projector(*params.values_at(:granite_action, :granite_projector))&.controller_class end |
#prepare_params!(params, *_args) ⇒ Object
31 32 33 |
# File 'lib/granite/dispatcher.rb', line 31 def prepare_params!(params, *_args) params end |
#reset! ⇒ Object
Make dispatcher object pristine, clean memoist cache.
8 9 10 |
# File 'lib/granite/dispatcher.rb', line 8 def reset! unmemoize_all end |
#serve(req) ⇒ Object
18 19 20 21 |
# File 'lib/granite/dispatcher.rb', line 18 def serve(req) controller, action = detect_controller_class_and_action_name(req) controller.action(action).call(req.env) end |