Class: Cyberweb::CGI::Session::MemoryStore
- Inherits:
-
Object
- Object
- Cyberweb::CGI::Session::MemoryStore
- Defined in:
- lib/cyberweb/cgi/session/memory_store.rb
Overview
#
MemoryStore
In-memory session storage class.
Implements session storage as a global in-memory hash. Session data will only persist for as long as the Ruby interpreter instance does.
#
Constant Summary collapse
- GLOBAL_HASH_TABLE =
#
GLOBAL_HASH_TABLE
#
{}
Instance Method Summary collapse
-
#close ⇒ Object
# Close session storage.
-
#delete ⇒ Object
# === delete.
-
#initialize(session, option = nil) ⇒ MemoryStore
constructor
# === initialize.
-
#restore ⇒ Object
# === restore.
-
#update ⇒ Object
# === update.
Constructor Details
#initialize(session, option = nil) ⇒ MemoryStore
#
initialize
Create a new MemoryStore instance.
session
is the session this instance is associated with.
option
is a list of initialisation options. None are currently recognized.
#
37 38 39 40 41 42 43 44 45 46 47 |
# File 'lib/cyberweb/cgi/session/memory_store.rb', line 37 def initialize( session, option = nil ) @session_id = session.session_id unless GLOBAL_HASH_TABLE.key?(@session_id) unless session.new_session raise CGI::Session::NoSession, 'uninitialized session' end GLOBAL_HASH_TABLE[@session_id] = {} end end |
Instance Method Details
#close ⇒ Object
#
Close session storage.
A no-op.
#
76 77 78 |
# File 'lib/cyberweb/cgi/session/memory_store.rb', line 76 def close # don't need to close end |
#delete ⇒ Object
#
delete
Delete the session state.
#
85 86 87 |
# File 'lib/cyberweb/cgi/session/memory_store.rb', line 85 def delete GLOBAL_HASH_TABLE.delete(@session_id) end |
#restore ⇒ Object
#
restore
Restore session state.
Returns session data as a hash.
#
56 57 58 |
# File 'lib/cyberweb/cgi/session/memory_store.rb', line 56 def restore GLOBAL_HASH_TABLE[@session_id] end |
#update ⇒ Object
#
update
Update session state.
A no-op.
#
67 68 69 |
# File 'lib/cyberweb/cgi/session/memory_store.rb', line 67 def update # don't need to update; hash is shared end |