Sha256: 516c801b26ec2d4292d3f8e2294dbc9b7caf40f44c5ca51fe67013639776e317
Contents?: true
Size: 1.56 KB
Versions: 3
Compression:
Stored size: 1.56 KB
Contents
require 'omf_base/lobject' module OMF::Web # Keeps session state. # # TODO: Implement cleanup thread # class SessionStore < OMF::Base::LObject @@sessions = {} def self.[](key, domain) self.session["#{domain}:#{key}"] end def self.[]=(key, domain, value) self.session["#{domain}:#{key}"] = value end def self.session() sid = session_id session = @@sessions[sid] ||= {:content => {}} #puts "STORE>> #{sid} = #{session[:content].keys.inspect}" session[:ts] = Time.now session[:content] end def self.session_id sid = Thread.current["sessionID"] raise "Missing session id 'sid'" if sid.nil? sid end 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 def self.find_across_sessions(&block) @@sessions.values.map { |v| v[:content] }.find(&block) end # Return a session context which will execute block given to # #call in this session context # def self.session_context SessionContext.new end end # SessionStore class SessionContext def initialize @sid = Thread.current["sessionID"] end def call(&block) Thread.current["sessionID"] = @sid block.call end end end # OMF:Web
Version data entries
3 entries across 3 versions & 1 rubygems
Version | Path |
---|---|
omf_web-1.2.4 | lib/omf-web/session_store.rb |
omf_web-1.2.3 | lib/omf-web/session_store.rb |
omf_web-1.2.2 | lib/omf-web/session_store.rb |