Class: OMF::Web::SessionStore

Inherits:
Common::LObject show all
Defined in:
lib/omf-web/session_store.rb

Overview

Keeps session state.

TODO: Implement cleanup thread

Constant Summary collapse

@@sessions =
{}

Class Method Summary collapse

Methods inherited from Common::LObject

#initialize

Methods included from Common::Loggable

#_logger, #debug, #error, #fatal, #info, init_log, logger, set_environment, #warn

Constructor Details

This class inherits a constructor from OMF::Common::LObject

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_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(sid = nil) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/omf-web/session_store.rb', line 22

def self.session(sid = nil)
  unless sid
    sid = Thread.current["sessionID"]
  end
  unless sid
    raise "Missing session id 'sid'"
  end
  
  session = @@sessions[sid] ||= {:content => {}}
  #puts "STORE>> #{sid} = #{session[:content].keys.inspect}"
  session[:ts] = Time.now
  session[:content]
end