class RodaSessionMiddleware
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 Methods
Source
# File lib/roda/session_middleware.rb, line 160 def initialize(app, opts) mid = Class.new(Roda) Roda::RodaPlugins.set_temp_name(mid){"RodaSessionMiddleware::_RodaSubclass"} mid.plugin :sessions, opts @req_class = mid::RodaRequest @req_class.send(:include, RequestMethods) @app = app end
Setup the middleware, passing opts
as the Roda
sessions plugin options.
Public Instance Methods
Source
# File lib/roda/session_middleware.rb, line 172 def call(env) session = env['rack.session'] = SessionHash.new(@req_class.new(nil, env)) res = @app.call(env) if session.loaded? session.req.persist_session(res[1], session.data) end res end
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.