Class: Mack::Session
Overview
A holder for the session information. This objects gets stored using the Cachetastic system. For more information about how Cachetastic works see the RDoc for that gem. The session cookie name defaults to: _mack_session_id but can be changed using the configatron system like such:
mack::session_id: _my_cool_app_sess_id
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
The id of the session.
Instance Method Summary collapse
-
#[](key) ⇒ Object
Finds what you’re looking for in the session, if it exists.
-
#[]=(key, value) ⇒ Object
Sets a value into the session.
-
#delete(key) ⇒ Object
Deletes a value from the session.
-
#initialize(id) ⇒ Session
constructor
A new instance of Session.
- #inspect ⇒ Object
-
#reset! ⇒ Object
Clears out the session.
Constructor Details
#initialize(id) ⇒ Session
Returns a new instance of Session.
12 13 14 15 |
# File 'lib/mack/sessions/session.rb', line 12 def initialize(id) @id = id @sess_hash = {} end |
Instance Attribute Details
#id ⇒ Object (readonly)
The id of the session.
10 11 12 |
# File 'lib/mack/sessions/session.rb', line 10 def id @id end |
Instance Method Details
#[](key) ⇒ Object
Finds what you’re looking for in the session, if it exists. If what you’re looking for doesn’t exist, it returns nil.
19 20 21 |
# File 'lib/mack/sessions/session.rb', line 19 def [](key) sess_hash[key.to_sym] end |
#[]=(key, value) ⇒ Object
Sets a value into the session.
24 25 26 |
# File 'lib/mack/sessions/session.rb', line 24 def []=(key, value) sess_hash[key.to_sym] = value end |
#delete(key) ⇒ Object
Deletes a value from the session
34 35 36 |
# File 'lib/mack/sessions/session.rb', line 34 def delete(key) @sess_hash.delete(key.to_sym) end |
#inspect ⇒ Object
38 39 40 |
# File 'lib/mack/sessions/session.rb', line 38 def inspect "#{self.id}: #{@sess_hash.inspect}" end |
#reset! ⇒ Object
Clears out the session.
29 30 31 |
# File 'lib/mack/sessions/session.rb', line 29 def reset! @sess_hash = {} end |