Class: Merb::MemorySession
- Defined in:
- lib/merb-core/dispatch/session/memory.rb
Overview
Instance Attribute Summary collapse
-
#data ⇒ Object
Returns the value of attribute data.
-
#needs_new_cookie ⇒ Object
Returns the value of attribute needs_new_cookie.
-
#session_id ⇒ Object
Returns the value of attribute session_id.
Class Method Summary collapse
-
.generate ⇒ Object
Generates a new session ID and creates a new session.
-
.persist(session_id) ⇒ Object
Parameters session_id<String:: The ID of the session to retrieve.
Instance Method Summary collapse
-
#[](k) ⇒ Object
Parameters k<~to_s>:: The key of the session parameter to retrieve.
-
#[]=(k, v) ⇒ Object
Parameters k<~to_s>:: The key of the session parameter to set.
-
#delete ⇒ Object
Deletes the session by emptying stored data.
-
#each(&b) ⇒ Object
Yields the session data to an each block.
-
#initialize(session_id) ⇒ MemorySession
constructor
Parameters session_id<String>:: A unique identifier for this session.
-
#loaded? ⇒ Boolean
Returns Boolean:: True if session has been loaded already.
-
#refresh_expiration ⇒ Object
Recreates the cookie with the default expiration time.
-
#regenerate ⇒ Object
Regenerate the Session ID.
Constructor Details
#initialize(session_id) ⇒ MemorySession
Parameters
- session_id<String>
-
A unique identifier for this session.
54 55 56 57 |
# File 'lib/merb-core/dispatch/session/memory.rb', line 54 def initialize(session_id) @session_id = session_id @data = {} end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(name, *args, &block) ⇒ Object (private)
Attempts to redirect any messages to the data object.
143 144 145 |
# File 'lib/merb-core/dispatch/session/memory.rb', line 143 def method_missing(name, *args, &block) @data.send(name, *args, &block) end |
Instance Attribute Details
#data ⇒ Object
Returns the value of attribute data.
49 50 51 |
# File 'lib/merb-core/dispatch/session/memory.rb', line 49 def data @data end |
#needs_new_cookie ⇒ Object
Returns the value of attribute needs_new_cookie.
50 51 52 |
# File 'lib/merb-core/dispatch/session/memory.rb', line 50 def @needs_new_cookie end |
#session_id ⇒ Object
Returns the value of attribute session_id.
48 49 50 |
# File 'lib/merb-core/dispatch/session/memory.rb', line 48 def session_id @session_id end |
Class Method Details
.generate ⇒ Object
Generates a new session ID and creates a new session.
Returns
- MemorySession
-
The new session.
65 66 67 68 |
# File 'lib/merb-core/dispatch/session/memory.rb', line 65 def generate sid = Merb::SessionMixin::rand_uuid MemorySessionContainer[sid] = new(sid) end |
.persist(session_id) ⇒ Object
Parameters
- session_id<String
-
The ID of the session to retrieve.
Returns
- Array
-
A pair consisting of a MemorySession and the session’s ID. If no sessions matched session_id, a new MemorySession will be generated.
77 78 79 80 81 82 83 84 85 |
# File 'lib/merb-core/dispatch/session/memory.rb', line 77 def persist(session_id) if session_id session = MemorySessionContainer[session_id] end unless session session = generate end [session, session.session_id] end |
Instance Method Details
#[](k) ⇒ Object
Parameters
- k<~to_s>
-
The key of the session parameter to retrieve.
Returns
- String
-
The value of the session parameter.
128 129 130 |
# File 'lib/merb-core/dispatch/session/memory.rb', line 128 def [](k) @data[k] end |
#[]=(k, v) ⇒ Object
Parameters
- k<~to_s>
-
The key of the session parameter to set.
- v<~to_s>
-
The value of the session parameter to set.
119 120 121 |
# File 'lib/merb-core/dispatch/session/memory.rb', line 119 def []=(k, v) @data[k] = v end |
#delete ⇒ Object
Deletes the session by emptying stored data.
106 107 108 |
# File 'lib/merb-core/dispatch/session/memory.rb', line 106 def delete @data = {} end |
#each(&b) ⇒ Object
Yields the session data to an each block.
Parameter
- &b
-
The block to pass to each.
136 137 138 |
# File 'lib/merb-core/dispatch/session/memory.rb', line 136 def each(&b) @data.each(&b) end |
#loaded? ⇒ Boolean
Returns
- Boolean
-
True if session has been loaded already.
112 113 114 |
# File 'lib/merb-core/dispatch/session/memory.rb', line 112 def loaded? !! @data end |
#refresh_expiration ⇒ Object
Recreates the cookie with the default expiration time. Useful during log in for pushing back the expiration date.
101 102 103 |
# File 'lib/merb-core/dispatch/session/memory.rb', line 101 def refresh_expiration self.=true end |
#regenerate ⇒ Object
Regenerate the Session ID
90 91 92 93 94 95 96 97 |
# File 'lib/merb-core/dispatch/session/memory.rb', line 90 def regenerate new_sid = Merb::SessionMixin::rand_uuid old_sid = @session_id MemorySessionContainer[new_sid] = MemorySessionContainer[old_sid] @session_id = new_sid MemorySessionContainer.delete(old_sid) self.=true end |