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 261 def persist_session(headers, session) 262 opts = roda_class.opts[:sessions] 263 264 if session.empty? 265 if env[SESSION_SERIALIZED] 266 # If session was submitted and is now empty, remove the cookie 267 Rack::Utils.delete_cookie_header!(headers, opts[:key], opts[:remove_cookie_options]) 268 # else 269 # If no session was submitted, and the session is empty 270 # then there is no need to do anything 271 end 272 elsif cookie_value = _serialize_session(session) 273 cookie = Hash[opts[:cookie_options]] 274 cookie[:value] = cookie_value 275 cookie[:secure] = true if !cookie.has_key?(:secure) && ssl? 276 Rack::Utils.set_cookie_header!(headers, opts[:key], cookie) 277 end 278 279 if env[SESSION_DELETE_RACK_COOKIE] 280 Rack::Utils.delete_cookie_header!(headers, opts[:upgrade_from_rack_session_cookie_key], opts[:upgrade_from_rack_session_cookie_options]) 281 end 282 283 nil 284 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 242 def session 243 @env['rack.session'] ||= _load_session 244 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 247 def session_created_at 248 session 249 Time.at(@env[SESSION_CREATED_AT]) if @env[SESSION_SERIALIZED] 250 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 253 def session_updated_at 254 session 255 Time.at(@env[SESSION_UPDATED_AT]) if @env[SESSION_SERIALIZED] 256 end