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