Module: Sinatra::Session::Helpers
- Defined in:
- lib/sinatra/session.rb
Overview
Request-level helper methods for Sinatra routes.
Instance Method Summary collapse
-
#session! ⇒ Object
Redirects the client to the URL given in the
session_failsetting if #session? returnsfalse. -
#session? ⇒ Boolean
Returns
trueif the current session is valid,falseotherwise. -
#session_end!(destroy = true) ⇒ Object
After this method is called, calls to #session? will return
false. -
#session_start! ⇒ Object
After this method is called, calls to #session? will return
true.
Instance Method Details
#session! ⇒ Object
Redirects the client to the URL given in the session_fail setting if #session? returns false.
34 35 36 |
# File 'lib/sinatra/session.rb', line 34 def session! redirect(settings.session_fail) unless session? end |
#session? ⇒ Boolean
Returns true if the current session is valid, false otherwise.
28 29 30 |
# File 'lib/sinatra/session.rb', line 28 def session? !! session['sinatra.session'] end |
#session_end!(destroy = true) ⇒ Object
After this method is called, calls to #session? will return false. If you want to keep the old session data around in the cookie for some reason, set destroy to false.
19 20 21 22 23 24 25 |
# File 'lib/sinatra/session.rb', line 19 def session_end!(destroy=true) if destroy session.clear else session['sinatra.session'] = false end end |
#session_start! ⇒ Object
After this method is called, calls to #session? will return true.
12 13 14 |
# File 'lib/sinatra/session.rb', line 12 def session_start! session['sinatra.session'] = true end |