Class: Ooor::SessionHandler

Inherits:
Object
  • Object
show all
Defined in:
lib/ooor/session_handler.rb

Overview

The SessionHandler allows to retrieve a session with its loaded proxies to OpenERP

Instance Method Summary collapse

Instance Method Details

#connectionsObject



57
# File 'lib/ooor/session_handler.rb', line 57

def connections; @connections ||= {}; end

#get_web_session(key) ⇒ Object



48
49
50
# File 'lib/ooor/session_handler.rb', line 48

def get_web_session(key)
  Ooor.cache.read(key)
end

#noweb_session_spec(config) ⇒ Object



9
10
11
# File 'lib/ooor/session_handler.rb', line 9

def noweb_session_spec(config)
  "#{config[:url]}-#{config[:database]}-#{config[:username]}"
end

#register_session(session) ⇒ Object



31
32
33
34
35
36
37
38
39
40
41
# File 'lib/ooor/session_handler.rb', line 31

def register_session(session)
  if session.config[:session_sharing]
    spec = session.web_session[:session_id]
  elsif session.id != :noweb
    spec = session.id
  else
    spec = noweb_session_spec(session.config)
  end
  set_web_session(spec, session.web_session)
  sessions[spec] = session
end

#reset!Object



43
44
45
46
# File 'lib/ooor/session_handler.rb', line 43

def reset!
  @sessions = {}
  @connections = {}
end

#retrieve_session(config, id = nil, web_session = {}) ⇒ Object



13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/ooor/session_handler.rb', line 13

def retrieve_session(config, id=nil, web_session={})
  id ||= SecureRandom.hex(16)
  if id == :noweb
    spec = noweb_session_spec(config)
  else
    spec = id
  end
  if config[:reload] || !s = sessions[spec]
    config = Ooor.default_config.merge(config) if Ooor.default_config.is_a? Hash
    Ooor::Session.new(config, web_session, id)
  elsif noweb_session_spec(s.config) != noweb_session_spec(config)
    config = Ooor.default_config.merge(config) if Ooor.default_config.is_a? Hash
    Ooor::Session.new(config, web_session, id)
  else
    s.tap {|s| s.web_session.merge!(web_session)} #TODO merge config also?
  end
end

#sessionsObject



56
# File 'lib/ooor/session_handler.rb', line 56

def sessions; @sessions ||= {}; end

#set_web_session(key, web_session) ⇒ Object



52
53
54
# File 'lib/ooor/session_handler.rb', line 52

def set_web_session(key, web_session)
  Ooor.cache.write(key, web_session)
end