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   Roda::RodaPlugins.set_temp_name(mid){"RodaSessionMiddleware::_RodaSubclass"}
163   mid.plugin :sessions, opts
164   @req_class = mid::RodaRequest
165   @req_class.send(:include, RequestMethods)
166   @app = app
167 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
172 def call(env)
173   session = env['rack.session'] = SessionHash.new(@req_class.new(nil, env))
174 
175   res = @app.call(env)
176 
177   if session.loaded?
178     session.req.persist_session(res[1], session.data)
179   end
180 
181   res
182 end