Sha256: 864669a34cea0a75b437dc467e164ecfc6002841f94cb9e4bd2a29ebcf22fe9c

Contents?: true

Size: 1.32 KB

Versions: 104

Compression:

Stored size: 1.32 KB

Contents

# All roads lead here
#
# 1. AWS Lambda: PostsController - Rack::Adapter - Jets.application.call
# 2. Local server:  config.ru - run Jet.application - Jets.application.call
#
# Then eventually:
#
#   Jets.application.call - Middleware stack - Jets::Controller::Middleware::Main
#
module Jets::Controller::Middleware
  class Main
    def initialize(env)
      @env = env
      @controller = env['jets.controller']
      @event = env['lambda.event']
      @context = env['lambda.context']
      @meth = env['lambda.meth']
    end

    def call
      dup.call!
    end

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

    # Common setup logical at this point of middleware processing right before
    # calling any controller actions.
    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

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

Version data entries

104 entries across 104 versions & 3 rubygems

Version Path
jets_bb_fork-0.0.4 lib/jets/controller/middleware/main.rb
jets-1.9.32 lib/jets/controller/middleware/main.rb
jets-1.9.31 lib/jets/controller/middleware/main.rb
jets-1.9.30 lib/jets/controller/middleware/main.rb
jets-1.9.29 lib/jets/controller/middleware/main.rb
jets-1.9.28 lib/jets/controller/middleware/main.rb
jets-1.9.27 lib/jets/controller/middleware/main.rb
jets-1.9.26 lib/jets/controller/middleware/main.rb
jets-1.9.25 lib/jets/controller/middleware/main.rb
jets-1.9.24 lib/jets/controller/middleware/main.rb
jets-1.9.23 lib/jets/controller/middleware/main.rb
jets-1.9.22 lib/jets/controller/middleware/main.rb
jets-1.9.21 lib/jets/controller/middleware/main.rb
jets-1.9.20 lib/jets/controller/middleware/main.rb
jets-1.9.19 lib/jets/controller/middleware/main.rb
jets-1.9.18 lib/jets/controller/middleware/main.rb
jets-1.9.17 lib/jets/controller/middleware/main.rb
jets-1.9.16 lib/jets/controller/middleware/main.rb
jets-1.9.15 lib/jets/controller/middleware/main.rb
jets-1.9.14 lib/jets/controller/middleware/main.rb