Class: OMF::Web::SessionStore
- Inherits:
-
Base::LObject
- Object
- Base::LObject
- OMF::Web::SessionStore
- Defined in:
- lib/omf-web/session_store.rb
Overview
Keeps session state.
TODO: Implement cleanup thread
Constant Summary collapse
- @@sessions =
{}
Class Method Summary collapse
- .[](key, domain) ⇒ Object
- .[]=(key, domain, value) ⇒ Object
- .find_across_sessions(&block) ⇒ Object
- .find_tab_from_path(comp_path) ⇒ Object
- .session ⇒ Object
-
.session_context ⇒ Object
Return a session context which will execute block given to #call in this session context.
- .session_id ⇒ Object
Class Method Details
.[](key, domain) ⇒ Object
14 15 16 |
# File 'lib/omf-web/session_store.rb', line 14 def self.[](key, domain) self.session["#{domain}:#{key}"] end |
.[]=(key, domain, value) ⇒ Object
18 19 20 |
# File 'lib/omf-web/session_store.rb', line 18 def self.[]=(key, domain, value) self.session["#{domain}:#{key}"] = value end |
.find_across_sessions(&block) ⇒ Object
48 49 50 |
# File 'lib/omf-web/session_store.rb', line 48 def self.find_across_sessions(&block) @@sessions.values.map { |v| v[:content] }.find(&block) end |
.find_tab_from_path(comp_path) ⇒ Object
36 37 38 39 40 41 42 43 44 45 46 |
# File 'lib/omf-web/session_store.rb', line 36 def self.find_tab_from_path(comp_path) sid = comp_path.shift unless session = self.session(sid) raise "Can't find session '#{sid}', may have timed out" end tid = comp_path.shift.to_sym unless tab_inst = session[tid] raise "Can't find tab '#{tid}'" end {:sid => sid, :tab_inst => tab_inst, :sub_path => comp_path} end |
.session ⇒ Object
22 23 24 25 26 27 28 |
# File 'lib/omf-web/session_store.rb', line 22 def self.session() sid = session_id session = @@sessions[sid] ||= {:content => {}} #puts "STORE>> #{sid} = #{session[:content].keys.inspect}" session[:ts] = Time.now session[:content] end |
.session_context ⇒ Object
Return a session context which will execute block given to #call in this session context
55 56 57 |
# File 'lib/omf-web/session_store.rb', line 55 def self.session_context SessionContext.new end |
.session_id ⇒ Object
30 31 32 33 34 |
# File 'lib/omf-web/session_store.rb', line 30 def self.session_id sid = Thread.current["sessionID"] raise "Missing session ID in thread context" if sid.nil? sid end |