Class: Colossus::Engine::Memory::ClientSessionStore
- Inherits:
-
Object
- Object
- Colossus::Engine::Memory::ClientSessionStore
- Defined in:
- lib/colossus/engines/memory/client_session_store.rb
Overview
Represents all the different sessions of a user. It can find
the global status of the user given all the different status.
Instance Attribute Summary collapse
-
#last_status ⇒ Object
readonly
Returns the value of attribute last_status.
-
#sessions ⇒ Object
Returns the value of attribute sessions.
Instance Method Summary collapse
- #[](session_id) ⇒ Object
- #[]=(session_id, session_status) ⇒ Object
- #delete(session_id) ⇒ Object
-
#initialize ⇒ ClientSessionStore
constructor
A new instance of ClientSessionStore.
- #last_seen ⇒ Object
- #status ⇒ Object
- #status_changed? ⇒ Boolean
Constructor Details
#initialize ⇒ ClientSessionStore
Returns a new instance of ClientSessionStore.
10 11 12 13 14 15 |
# File 'lib/colossus/engines/memory/client_session_store.rb', line 10 def initialize @sessions = Hash.new do |hash, key| hash[key] = Colossus::Engine::Memory::ClientSession.new end @last_status = DISCONNECTED end |
Instance Attribute Details
#last_status ⇒ Object (readonly)
Returns the value of attribute last_status.
7 8 9 |
# File 'lib/colossus/engines/memory/client_session_store.rb', line 7 def last_status @last_status end |
#sessions ⇒ Object
Returns the value of attribute sessions.
8 9 10 |
# File 'lib/colossus/engines/memory/client_session_store.rb', line 8 def sessions @sessions end |
Instance Method Details
#[](session_id) ⇒ Object
40 41 42 |
# File 'lib/colossus/engines/memory/client_session_store.rb', line 40 def [](session_id) sessions[session_id] end |
#[]=(session_id, session_status) ⇒ Object
44 45 46 47 |
# File 'lib/colossus/engines/memory/client_session_store.rb', line 44 def []=(session_id, session_status) @last_status = status sessions[session_id].status = session_status end |
#delete(session_id) ⇒ Object
49 50 51 |
# File 'lib/colossus/engines/memory/client_session_store.rb', line 49 def delete(session_id) sessions.delete(session_id) end |
#last_seen ⇒ Object
30 31 32 33 34 |
# File 'lib/colossus/engines/memory/client_session_store.rb', line 30 def last_seen sessions.values.reduce(Time.new(0)) do |memo, session| session.last_seen > memo ? session.last_seen : memo end end |
#status ⇒ Object
17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/colossus/engines/memory/client_session_store.rb', line 17 def status sessions.values.reduce(DISCONNECTED) do |memo, session| case session.status when ACTIVE session.status when AWAY memo == ACTIVE ? memo : session.status else memo end end end |
#status_changed? ⇒ Boolean
36 37 38 |
# File 'lib/colossus/engines/memory/client_session_store.rb', line 36 def status_changed? last_status != status end |