Class: Granite::Dispatcher

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

Instance Method Summary collapse

Instance Method Details

#callObject



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

#constraintsObject



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.slice(:granite_action, :granite_projector).symbolize_keys)&.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