Class: CGI::Session::PStore

Inherits:
Object show all
Defined in:
lib/action_controller/cgi_ext/session.rb

Overview

  • Don't require 'digest/md5' whenever a new session is started.

Instance Method Summary collapse

Constructor Details

#initialize(session, option = {}) ⇒ PStore

Returns a new instance of PStore.


31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
# File 'lib/action_controller/cgi_ext/session.rb', line 31

def initialize(session, option={})
  dir = option['tmpdir'] || Dir::tmpdir
  prefix = option['prefix'] || ''
  id = session.session_id
  md5 = Digest::MD5.hexdigest(id)[0,16]
  path = dir+"/"+prefix+md5
  path.untaint
  if File::exist?(path)
    @hash = nil
  else
    unless session.new_session
      raise CGI::Session::NoSession, "uninitialized session"
    end
    @hash = {}
  end
  @p = ::PStore.new(path)
  @p.transaction do |p|
    File.chmod(0600, p.path)
  end
end