Module: Merb::SessionMixin
- Defined in:
- lib/merb-core/dispatch/session.rb,
lib/merb-core/dispatch/session/cookie.rb,
lib/merb-core/dispatch/session/memory.rb,
lib/merb-core/dispatch/session/memcached.rb
Class Method Summary collapse
-
.finalize_session_exception_callbacks(&block) ⇒ Object
Adds a callback to the list of callbacks run when exception is raised on session finalization, so you can recover.
-
.needs_new_cookie! ⇒ Object
Marks this session as needing a new cookie.
-
.persist_exception_callbacks(&block) ⇒ Object
Adds a callback to the list of callbacks run when exception is raised on session persisting, so you can recover.
-
.rand_uuid ⇒ Object
Returns String:: A random 32 character string for use as a unique session ID.
Instance Method Summary collapse
-
#finalize_session ⇒ Object
Finalizes the session by storing the session ID in a cookie, if the session has changed.
-
#session_store_type ⇒ Object
Returns String:: The session store type, i.e.
-
#set_session_id_cookie(key) ⇒ Object
Sets the session id cookie, along with the correct expiry and domain – used for new or reset sessions.
-
#setup_session ⇒ Object
Adds a before and after dispatch hook for setting up the memcached session store.
Class Method Details
.finalize_session_exception_callbacks(&block) ⇒ Object
Adds a callback to the list of callbacks run when exception is raised on session finalization, so you can recover.
See session mixins documentation for details on session finalization.
Params
- &block
-
A block to be added to the callbacks that will be executed if there’s exception on session finalization.
48 49 50 51 52 53 54 |
# File 'lib/merb-core/dispatch/session.rb', line 48 def finalize_session_exception_callbacks(&block) if block_given? @_finalize_session_exception_callbacks << block else @_finalize_session_exception_callbacks end end |
.needs_new_cookie! ⇒ Object
Marks this session as needing a new cookie.
33 34 35 |
# File 'lib/merb-core/dispatch/session.rb', line 33 def @_new_cookie = true end |
.persist_exception_callbacks(&block) ⇒ Object
Adds a callback to the list of callbacks run when exception is raised on session persisting, so you can recover.
See session mixins documentation for details on session persisting.
Params
- &block
-
A block to be added to the callbacks that will be executed if there’s exception on session persisting.
67 68 69 70 71 72 73 |
# File 'lib/merb-core/dispatch/session.rb', line 67 def persist_exception_callbacks(&block) if block_given? @_persist_exception_callbacks << block else @_persist_exception_callbacks end end |
.rand_uuid ⇒ Object
Returns
- String
-
A random 32 character string for use as a unique session ID.
19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/merb-core/dispatch/session.rb', line 19 def rand_uuid values = [ rand(0x0010000), rand(0x0010000), rand(0x0010000), rand(0x0010000), rand(0x0010000), rand(0x1000000), rand(0x1000000), ] "%04x%04x%04x%04x%04x%06x%06x" % values end |
Instance Method Details
#finalize_session ⇒ Object
Finalizes the session by storing the session ID in a cookie, if the session has changed.
20 21 22 23 24 25 26 27 |
# File 'lib/merb-core/dispatch/session/cookie.rb', line 20 def finalize_session new_session = request.session. if @original_session != new_session = {:expires => (Time.now + _session_expiry)} [:domain] = if .(_session_id_key, new_session, ) end end |
#session_store_type ⇒ Object
Returns
- String
-
The session store type, i.e. “memcache”.
31 32 33 |
# File 'lib/merb-core/dispatch/session/cookie.rb', line 31 def session_store_type "cookie" end |
#set_session_id_cookie(key) ⇒ Object
Sets the session id cookie, along with the correct expiry and domain – used for new or reset sessions
6 7 8 9 10 11 12 |
# File 'lib/merb-core/dispatch/session.rb', line 6 def (key) = {} [:value] = key [:expires] = Time.now + _session_expiry if _session_expiry > 0 [:domain] = if [_session_id_key] = end |
#setup_session ⇒ Object
Adds a before and after dispatch hook for setting up the memcached session store.
Parameters
- base<Class>
-
The class to which the SessionMixin is mixed into.
13 14 15 16 |
# File 'lib/merb-core/dispatch/session/cookie.rb', line 13 def setup_session request.session = Merb::CookieSession.new([_session_id_key], _session_secret_key) @original_session = request.session. end |