Public Instance methods
persist_session(headers, session)
Persist the session data as a cookie. If transparently upgrading from Rack::Session::Cookie, mark the related cookie for expiration so it isn’t sent in the future.
[show source]
# File lib/roda/plugins/sessions.rb 257 def persist_session(headers, session) 258 opts = roda_class.opts[:sessions] 259 260 if session.empty? 261 if env[SESSION_SERIALIZED] 262 # If session was submitted and is now empty, remove the cookie 263 Rack::Utils.delete_cookie_header!(headers, opts[:key], opts[:remove_cookie_options]) 264 # else 265 # If no session was submitted, and the session is empty 266 # then there is no need to do anything 267 end 268 elsif cookie_value = _serialize_session(session) 269 cookie = Hash[opts[:cookie_options]] 270 cookie[:value] = cookie_value 271 cookie[:secure] = true if !cookie.has_key?(:secure) && ssl? 272 Rack::Utils.set_cookie_header!(headers, opts[:key], cookie) 273 end 274 275 if env[SESSION_DELETE_RACK_COOKIE] 276 Rack::Utils.delete_cookie_header!(headers, opts[:upgrade_from_rack_session_cookie_key], opts[:upgrade_from_rack_session_cookie_options]) 277 end 278 279 nil 280 end
session()
Load the session information from the cookie. With the sessions plugin, you must call this method to get the session, instead of trying to access the session directly through the request environment. For maximum compatibility with other software that uses rack sessions, this method stores the session in ‘rack.session’ in the request environment, but that does not happen until this method is called.
[show source]
# File lib/roda/plugins/sessions.rb 238 def session 239 @env['rack.session'] ||= _load_session 240 end
session_created_at()
The time the session was originally created. nil if there is no active session.
[show source]
# File lib/roda/plugins/sessions.rb 243 def session_created_at 244 session 245 Time.at(@env[SESSION_CREATED_AT]) if @env[SESSION_SERIALIZED] 246 end
session_updated_at()
The time the session was last updated. nil if there is no active session.
[show source]
# File lib/roda/plugins/sessions.rb 249 def session_updated_at 250 session 251 Time.at(@env[SESSION_UPDATED_AT]) if @env[SESSION_SERIALIZED] 252 end