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.


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 =
162   mid.plugin :sessions, opts
163   @req_class = mid::RodaRequest
164   @req_class.send(:include, RequestMethods)
165   @app = app
166 end

Public Instance methods


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'] =, env))
174   res =
176   if session.loaded?
177     session.req.persist_session(res[1],
178   end
180   res
181 end