class RodaSessionMiddleware

  1. lib/roda/session_middleware.rb
Superclass: Object

Session middleware that can be used in any Rack application that uses Roda’s sessions plugin for encrypted and signed cookies. See Roda::RodaPlugins::Sessions for details on options.

Methods

Public Class

  1. new

Public Instance

  1. call

Public Class methods

new(app, opts)

Setup the middleware, passing opts as the Roda sessions plugin options.

[show source]
    # File lib/roda/session_middleware.rb
160 def initialize(app, opts)
161   mid = Class.new(Roda)
162   mid.plugin :sessions, opts
163   @req_class = mid::RodaRequest
164   @req_class.send(:include, RequestMethods)
165   @app = app
166 end

Public Instance methods

call(env)

Initialize the session hash in the environment before calling the next application, and if the session has been loaded after the result has been returned, then persist the session in the cookie.

[show source]
    # File lib/roda/session_middleware.rb
171 def call(env)
172   session = env['rack.session'] = SessionHash.new(@req_class.new(nil, env))
173 
174   res = @app.call(env)
175 
176   if session.loaded?
177     session.req.persist_session(res[1], session.data)
178   end
179 
180   res
181 end