Module: Roda::RodaPlugins::Sessions::RequestMethods
- Defined in:
- lib/roda/plugins/sessions.rb
Instance Method Summary collapse
-
#persist_session(headers, session) ⇒ Object
Persist the session data as a cookie.
-
#session ⇒ Object
Load the session information from the cookie.
-
#session_created_at ⇒ Object
The time the session was originally created.
-
#session_updated_at ⇒ Object
The time the session was last updated.
Instance Method Details
#persist_session(headers, session) ⇒ Object
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.
256 257 258 259 260 261 262 263 264 265 266 267 268 269 270 271 272 273 274 275 276 277 278 279 |
# File 'lib/roda/plugins/sessions.rb', line 256 def persist_session(headers, session) opts = roda_class.opts[:sessions] if session.empty? if env[SESSION_SERIALIZED] # If session was submitted and is now empty, remove the cookie Rack::Utils.(headers, opts[:key], opts[:remove_cookie_options]) # else # If no session was submitted, and the session is empty # then there is no need to do anything end elsif = _serialize_session(session) = Hash[opts[:cookie_options]] [:value] = [:secure] = true if !.has_key?(:secure) && ssl? Rack::Utils.(headers, opts[:key], ) end if env[SESSION_DELETE_RACK_COOKIE] Rack::Utils.(headers, opts[:upgrade_from_rack_session_cookie_key], opts[:upgrade_from_rack_session_cookie_options]) end nil end |
#session ⇒ Object
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.
237 238 239 |
# File 'lib/roda/plugins/sessions.rb', line 237 def session @env['rack.session'] ||= _load_session end |
#session_created_at ⇒ Object
The time the session was originally created. nil if there is no active session.
242 243 244 245 |
# File 'lib/roda/plugins/sessions.rb', line 242 def session_created_at session Time.at(@env[SESSION_CREATED_AT]) if @env[SESSION_SERIALIZED] end |
#session_updated_at ⇒ Object
The time the session was last updated. nil if there is no active session.
248 249 250 251 |
# File 'lib/roda/plugins/sessions.rb', line 248 def session_updated_at session Time.at(@env[SESSION_UPDATED_AT]) if @env[SESSION_SERIALIZED] end |