Class Merb::SessionStoreContainer
In: merb-core/lib/merb-core/dispatch/session/store_container.rb
Parent: SessionContainer

Methods

finalize   generate   regenerate   retrieve   setup  

Attributes

_fingerprint  [RW]  :api: private

Public Class methods

Generates a new session ID and creates a new session.

Returns

SessionStoreContainer:The new session.

:api: private

[Source]

    # File merb-core/lib/merb-core/dispatch/session/store_container.rb, line 56
56:       def generate
57:         session = new(Merb::SessionMixin.rand_uuid)
58:         session.needs_new_cookie = true
59:         session
60:       end

Setup a new session or retreive an existing session.

Parameters

request<Merb::Request>:The Merb::Request that came in from Rack.

Notes

If no sessions were found, a new SessionContainer will be generated.

Returns

SessionContainer:a SessionContainer.

:api: private

[Source]

    # File merb-core/lib/merb-core/dispatch/session/store_container.rb, line 74
74:       def setup(request)
75:         session = retrieve(request.session_id)
76:         request.session = session
77:         # TODO Marshal.dump is slow - needs optimization
78:         session._fingerprint = Marshal.dump(request.session.to_hash).hash
79:         session
80:       end

Private Class methods

Parameters

session_id<String:The ID of the session to retrieve.

Returns

SessionStoreContainer:SessionStoreContainer instance with the session data. If no
  sessions matched session_id, a new SessionStoreContainer will be generated.

Notes

If there are persisted exceptions callbacks to execute, they all get executed when Memcache library raises an exception.

:api: private

[Source]

     # File merb-core/lib/merb-core/dispatch/session/store_container.rb, line 96
 96:       def retrieve(session_id)
 97:         unless session_id.blank?
 98:           begin
 99:             session_data = store.retrieve_session(session_id)
100:           rescue => err
101:             Merb.logger.warn!("Could not retrieve session from #{self.name}: #{err.message}")
102:           end
103:           # Not in container, but assume that cookie exists
104:           session_data = new(session_id) if session_data.nil?
105:         else
106:           # No cookie...make a new session_id
107:           session_data = generate
108:         end
109:         if session_data.is_a?(self)
110:           session_data
111:         else
112:           # Recreate using the existing session as the data, when switching 
113:           # from another session type for example, eg. cookie to memcached
114:           # or when the data is just a hash
115:           new(session_id).update(session_data)
116:         end
117:       end

Public Instance methods

Teardown and/or persist the current session.

If @_destroy is true, clear out the session completely, including removal of the session cookie itself.

Parameters

request<Merb::Request>:The Merb::Request that came in from Rack.

Notes

The data (self) is converted to a Hash first, since a container might choose to do a full Marshal on the data, which would make it persist attributes like ‘needs_new_cookie’, which it shouldn‘t.

:api: private

[Source]

     # File merb-core/lib/merb-core/dispatch/session/store_container.rb, line 135
135:     def finalize(request)
136:       if @_destroy
137:         store.delete_session(self.session_id)
138:         request.destroy_session_cookie
139:       else
140:         if _fingerprint != Marshal.dump(data = self.to_hash).hash
141:           begin
142:             store.store_session(request.session(self.class.session_store_type).session_id, data)
143:           rescue => err
144:             Merb.logger.warn!("Could not persist session to #{self.class.name}: #{err.message}")
145:           end
146:         end
147:         if needs_new_cookie || Merb::SessionMixin.needs_new_cookie?
148:           request.set_session_id_cookie(self.session_id)
149:         end
150:       end
151:     end

Regenerate the session ID.

:api: private

[Source]

     # File merb-core/lib/merb-core/dispatch/session/store_container.rb, line 156
156:     def regenerate
157:       store.delete_session(self.session_id)
158:       self.session_id = Merb::SessionMixin.rand_uuid
159:       store.store_session(self.session_id, self)
160:     end

[Validate]