Class: Iodine::Http::SessionManager::FileSessionStorage::SessionObject
- Inherits:
-
Object
- Object
- Iodine::Http::SessionManager::FileSessionStorage::SessionObject
- Defined in:
- lib/iodine/http/session.rb
Instance Method Summary collapse
-
#[](key) ⇒ Object
(also: #fetch)
Get a key from the session data store.
-
#[]=(key, value) ⇒ Object
(also: #store)
Stores a key in the session’s data store.
-
#clear ⇒ Object
Clears the session’s data.
-
#delete(key) ⇒ Object
Removes a key from the session’s data store.
-
#id ⇒ Object
returns the session id (the session cookie value).
-
#initialize(id) ⇒ SessionObject
constructor
called by the Plezi framework to initiate a session with the id requested.
-
#refresh ⇒ Object
Forced the session’s data to be reloaded.
-
#to_h ⇒ Hash
Returns a shallow copy of the current session data as a Hash.
-
#to_s ⇒ String
Returns the Session data in YAML format.
Constructor Details
#initialize(id) ⇒ SessionObject
called by the Plezi framework to initiate a session with the id requested
25 26 27 28 29 |
# File 'lib/iodine/http/session.rb', line 25 def initialize id @filename = File.join Dir.tmpdir, "iodine_#{Iodine::Http.session_token}_#{id}" @data ||= {} @id = id end |
Instance Method Details
#[](key) ⇒ Object Also known as: fetch
Get a key from the session data store.
Due to different considirations, all keys will be converted to strings, so that ‘“name” == :name` and `1234 == “1234”`. If you store two keys that evaluate as the same string, they WILL override each other.
38 39 40 41 42 |
# File 'lib/iodine/http/session.rb', line 38 def [] key key = key.to_s load @data[key] end |
#[]=(key, value) ⇒ Object Also known as: store
Stores a key in the session’s data store.
Due to different considirations, all keys will be converted to strings, so that ‘“name” == :name` and `1234 == “1234”`. If you store two keys that evaluate as the same string, they WILL override each other.
49 50 51 52 53 54 55 56 |
# File 'lib/iodine/http/session.rb', line 49 def []= key, value return delete key if value.nil? key = key.to_s load @data[key] = value save value end |
#clear ⇒ Object
Clears the session’s data.
80 81 82 83 |
# File 'lib/iodine/http/session.rb', line 80 def clear @data.clear nil end |
#delete(key) ⇒ Object
Removes a key from the session’s data store.
72 73 74 75 76 77 |
# File 'lib/iodine/http/session.rb', line 72 def delete key load ret = @data.delete key.to_s save ret end |
#id ⇒ Object
returns the session id (the session cookie value).
31 32 33 |
# File 'lib/iodine/http/session.rb', line 31 def id @id end |
#refresh ⇒ Object
Forced the session’s data to be reloaded
86 87 88 |
# File 'lib/iodine/http/session.rb', line 86 def refresh load end |
#to_h ⇒ Hash
Returns a shallow copy of the current session data as a Hash.
60 61 62 63 |
# File 'lib/iodine/http/session.rb', line 60 def to_h load @data.dup end |
#to_s ⇒ String
Returns the Session data in YAML format.
66 67 68 69 |
# File 'lib/iodine/http/session.rb', line 66 def to_s load @data.to_yaml end |