Class: Granite::Dispatcher

Inherits:
Object
  • Object
show all
Extended by:
Memoist
Defined in:
lib/granite/dispatcher.rb

Overview

:nodoc:

Instance Method Summary collapse

Instance Method Details

#callObject



13
14
15
16
17
# File 'lib/granite/dispatcher.rb', line 13

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.
  raise 'Dispatcher can\'t be used as a Rack app.'
end

#constraintsObject



24
25
26
# File 'lib/granite/dispatcher.rb', line 24

def constraints
  [->(req) { detect_controller_class_and_action_name(req).all?(&:present?) }]
end

#controller(params, *_args) ⇒ Object



28
29
30
# File 'lib/granite/dispatcher.rb', line 28

def controller(params, *_args)
  projector(*params.values_at(:granite_action, :granite_projector))&.controller_class
end

#prepare_params!(params, *_args) ⇒ Object



32
33
34
# File 'lib/granite/dispatcher.rb', line 32

def prepare_params!(params, *_args)
  params
end

#reset!Object

Make dispatcher object pristine, clean memoist cache.



9
10
11
# File 'lib/granite/dispatcher.rb', line 9

def reset!
  unmemoize_all
end

#serve(req) ⇒ Object



19
20
21
22
# File 'lib/granite/dispatcher.rb', line 19

def serve(req)
  controller, action = detect_controller_class_and_action_name(req)
  controller.action(action).call(req.env)
end