Class: Merb::ActiveRecordSession
- Inherits:
-
ActiveRecord::Base
- Object
- ActiveRecord::Base
- Merb::ActiveRecordSession
- Defined in:
- lib/merb/session/active_record_session.rb
Overview
ActiveRecordMixin
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Lazy-unmarshal session state.
-
#needs_new_cookie ⇒ Object
Returns the value of attribute needs_new_cookie.
Class Method Summary collapse
- .create_table! ⇒ Object
- .data_column_size_limit ⇒ Object
- .drop_table! ⇒ Object
-
.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_id
available in cookies. -
.reloadable? ⇒ Boolean
Don’t try to reload ARStore::Session in dev mode.
- .unmarshal(data) ⇒ Object
Instance Method Summary collapse
- #[](key) ⇒ Object
- #[]=(key, val) ⇒ Object
-
#delete ⇒ Object
Lazy-delete of session data.
-
#loaded? ⇒ Boolean
Has the session been loaded yet?.
-
#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
#data ⇒ Object
Lazy-unmarshal session state.
100 101 102 |
# File 'lib/merb/session/active_record_session.rb', line 100 def data @data ||= self.class.unmarshal(read_attribute(@@data_column_name)) || {} end |
#needs_new_cookie ⇒ Object
Returns the value of attribute needs_new_cookie.
27 28 29 |
# File 'lib/merb/session/active_record_session.rb', line 27 def end |
Class Method Details
.create_table! ⇒ Object
59 60 61 62 63 64 65 66 67 |
# File 'lib/merb/session/active_record_session.rb', line 59 def create_table! connection.execute "CREATE TABLE \#{table_name} (\nid INTEGER PRIMARY KEY,\n\#{connection.quote_column_name('session_id')} TEXT UNIQUE,\n\#{connection.quote_column_name(@@data_column_name)} TEXT(255)\n)\n" end |
.data_column_size_limit ⇒ Object
52 53 54 |
# File 'lib/merb/session/active_record_session.rb', line 52 def data_column_size_limit @data_column_size_limit ||= columns_hash[@@data_column_name].limit end |
.drop_table! ⇒ Object
69 70 71 |
# File 'lib/merb/session/active_record_session.rb', line 69 def drop_table! connection.execute "DROP TABLE #{table_name}" end |
.generate ⇒ Object
Generates a new session ID and creates a row for the new session in the database.
31 32 33 |
# File 'lib/merb/session/active_record_session.rb', line 31 def generate create(:session_id => Merb::SessionMixin::rand_uuid, :data => {}) end |
.marshal(data) ⇒ Object
56 |
# File 'lib/merb/session/active_record_session.rb', line 56 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.
37 38 39 40 41 42 43 44 45 |
# File 'lib/merb/session/active_record_session.rb', line 37 def persist(session_id) if session_id session = find_by_session_id(session_id) end unless session session = generate end [session, session.session_id] end |
.reloadable? ⇒ Boolean
Don’t try to reload ARStore::Session in dev mode.
48 49 50 |
# File 'lib/merb/session/active_record_session.rb', line 48 def reloadable? #:nodoc: false end |
.unmarshal(data) ⇒ Object
57 |
# File 'lib/merb/session/active_record_session.rb', line 57 def unmarshal(data) Marshal.load(Base64.decode64(data)) if data end |
Instance Method Details
#[](key) ⇒ Object
91 92 93 |
# File 'lib/merb/session/active_record_session.rb', line 91 def [](key) data[key] end |
#[]=(key, val) ⇒ Object
95 96 97 |
# File 'lib/merb/session/active_record_session.rb', line 95 def []=(key, val) data[key] = val end |
#delete ⇒ Object
Lazy-delete of session data
87 88 89 |
# File 'lib/merb/session/active_record_session.rb', line 87 def delete self.data = {} end |
#loaded? ⇒ Boolean
Has the session been loaded yet?
105 106 107 |
# File 'lib/merb/session/active_record_session.rb', line 105 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
82 83 84 |
# File 'lib/merb/session/active_record_session.rb', line 82 def refresh_expiration self. = true end |
#regenerate ⇒ Object
Regenerate the Session ID
75 76 77 78 |
# File 'lib/merb/session/active_record_session.rb', line 75 def regenerate update_attributes(:session_id => Merb::SessionMixin::rand_uuid) self. = true end |