Class: Merb::DataMapperSession
- Inherits:
-
DataMapper::Base
- Object
- DataMapper::Base
- Merb::DataMapperSession
- Defined in:
- lib/merb/session/data_mapper_session.rb
Instance Attribute Summary collapse
-
#needs_new_cookie ⇒ Object
Returns the value of attribute needs_new_cookie.
Class Method Summary collapse
-
.generate ⇒ Object
Generates a new session ID and creates a row for the new session in the database.
- .marshal(data) ⇒ Object
-
.persist(session_id) ⇒ Object
Gets the existing session based on the
session_idavailable in cookies. - .unmarshal(data) ⇒ Object
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, val) ⇒ Object
- #data ⇒ Object
-
#delete ⇒ Object
Lazy-delete of session data.
-
#refresh_expiration ⇒ Object
Recreates the cookie with the default expiration time Useful during log in for pushing back the expiration date.
-
#regenerate ⇒ Object
Regenerate the Session ID.
Instance Attribute Details
#needs_new_cookie ⇒ Object
Returns the value of attribute needs_new_cookie.
28 29 30 |
# File 'lib/merb/session/data_mapper_session.rb', line 28 def @needs_new_cookie end |
Class Method Details
.generate ⇒ Object
Generates a new session ID and creates a row for the new session in the database.
32 33 34 |
# File 'lib/merb/session/data_mapper_session.rb', line 32 def generate create(:session_id => Merb::SessionMixin::rand_uuid, :data =>{}) end |
.marshal(data) ⇒ Object
48 |
# File 'lib/merb/session/data_mapper_session.rb', line 48 def marshal(data) Base64.encode64(Marshal.dump(data)) if data end |
.persist(session_id) ⇒ Object
Gets the existing session based on the session_id available in cookies. If none is found, generates a new session.
38 39 40 41 42 43 44 45 46 |
# File 'lib/merb/session/data_mapper_session.rb', line 38 def persist(session_id) if session_id session = self[:session_id => session_id] end unless session session = generate end [session, session.session_id] end |
.unmarshal(data) ⇒ Object
49 |
# File 'lib/merb/session/data_mapper_session.rb', line 49 def unmarshal(data) Marshal.load(Base64.decode64(data)) if data end |
Instance Method Details
#[](key) ⇒ Object
70 71 72 |
# File 'lib/merb/session/data_mapper_session.rb', line 70 def [](key) data[key] end |
#[]=(key, val) ⇒ Object
74 75 76 |
# File 'lib/merb/session/data_mapper_session.rb', line 74 def []=(key, val) data[key] = val end |
#data ⇒ Object
78 79 80 |
# File 'lib/merb/session/data_mapper_session.rb', line 78 def data @unmarshalled_data || @unmarshalled_data = self.class.unmarshal(@data) end |
#delete ⇒ Object
Lazy-delete of session data
66 67 68 |
# File 'lib/merb/session/data_mapper_session.rb', line 66 def delete data = {} end |
#refresh_expiration ⇒ Object
Recreates the cookie with the default expiration time Useful during log in for pushing back the expiration date
61 62 63 |
# File 'lib/merb/session/data_mapper_session.rb', line 61 def refresh_expiration self. = true end |
#regenerate ⇒ Object
Regenerate the Session ID
53 54 55 56 57 |
# File 'lib/merb/session/data_mapper_session.rb', line 53 def regenerate self.session_id = Merb::SessionMixin::rand_uuid self. = true self.save end |