Class: Jets::Controller::Middleware::Main

Inherits:
Object
  • Object
show all
Defined in:
lib/jets/controller/middleware/main.rb

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(env) ⇒ Main

Returns a new instance of Main.



12
13
14
15
16
17
18
# File 'lib/jets/controller/middleware/main.rb', line 12

def initialize(env)
  @env = env
  @controller = env['jets.controller']
  @event = env['lambda.event']
  @context = env['lambda.context']
  @meth = env['lambda.meth']
end

Class Method Details

.call(env) ⇒ Object



41
42
43
44
# File 'lib/jets/controller/middleware/main.rb', line 41

def self.call(env)
  instance = new(env)
  instance.call
end

Instance Method Details

#callObject



20
21
22
# File 'lib/jets/controller/middleware/main.rb', line 20

def call
  dup.call!
end

#call!Object



24
25
26
27
# File 'lib/jets/controller/middleware/main.rb', line 24

def call!
  setup
  @controller.dispatch! # Returns triplet
end

#setupObject

Common setup logical at this point of middleware processing right before calling any controller actions.



31
32
33
34
35
36
37
38
39
# File 'lib/jets/controller/middleware/main.rb', line 31

def setup
  # We already recreated a mimicke rack env earlier as part of the very first
  # middleware layer. However, by the time the rack env reaches the main middleware
  # it could had been updated by other middlewares. We update the env here again.
  @controller.request.set_env!(@env)
  # This allows sesison helpers to work. Sessions are managed by
  # the Rack::Session::Cookie middleware by default.
  @controller.session = @env['rack.session'] || {}
end