Class: Merb::SessionStoreContainer

Inherits:
SessionContainer show all
Defined in:
lib/merb-core/dispatch/session/store_container.rb

Direct Known Subclasses

MemcacheSession, MemorySession

Instance Attribute Summary collapse

Attributes inherited from SessionContainer

#needs_new_cookie, #session_id

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from SessionContainer

#clear!, inherited, #initialize

Constructor Details

This class inherits a constructor from Merb::SessionContainer

Instance Attribute Details

#_fingerprintObject

:api: private



7
8
9
# File 'lib/merb-core/dispatch/session/store_container.rb', line 7

def _fingerprint
  @_fingerprint
end

Class Method Details

.generateObject

Generates a new session ID and creates a new session.

Returns

SessionStoreContainer

The new session.

:api: private



56
57
58
59
60
# File 'lib/merb-core/dispatch/session/store_container.rb', line 56

def generate
  session = new(Merb::SessionMixin.rand_uuid)
  session.needs_new_cookie = true
  session
end

.setup(request) ⇒ Object

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



74
75
76
77
78
79
80
# File 'lib/merb-core/dispatch/session/store_container.rb', line 74

def setup(request)
  session = retrieve(request.session_id)
  request.session = session
  # TODO Marshal.dump is slow - needs optimization
  session._fingerprint = Marshal.dump(request.session.to_hash).hash
  session
end

Instance Method Details

#finalize(request) ⇒ Object

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



135
136
137
138
139
140
141
142
143
144
145
146
147
148
149
150
151
# File 'lib/merb-core/dispatch/session/store_container.rb', line 135

def finalize(request)
  if @_destroy
    store.delete_session(self.session_id)
    request.destroy_session_cookie
  else
    if _fingerprint != Marshal.dump(data = self.to_hash).hash
      begin
        store.store_session(request.session(self.class.session_store_type).session_id, data)
      rescue => err
        Merb.logger.warn!("Could not persist session to #{self.class.name}: #{err.message}")
      end
    end
    if needs_new_cookie || Merb::SessionMixin.needs_new_cookie?
      request.set_session_id_cookie(self.session_id)
    end
  end
end

#regenerateObject

Regenerate the session ID.

:api: private



156
157
158
159
160
# File 'lib/merb-core/dispatch/session/store_container.rb', line 156

def regenerate
  store.delete_session(self.session_id)
  self.session_id = Merb::SessionMixin.rand_uuid
  store.store_session(self.session_id, self)
end