Class: CGI::Session::HiggsStore

Inherits:
Object
  • Object
show all
Defined in:
lib/cgi/session/higgs.rb

Overview

like cgi/session/pstore.rb

Constant Summary collapse

CVS_ID =

for ident(1)

'$Id: higgs.rb 841 2008-12-24 09:23:20Z toki $'

Instance Method Summary collapse

Constructor Details

#initialize(session, options = {}) ⇒ HiggsStore

Returns a new instance of HiggsStore.



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/cgi/session/higgs.rb', line 20

def initialize(session, options={})
  dir = options['tmpdir'] || Dir.tmpdir
  prefix = options['prefix'] || ''
  id = session.session_id
  name = options['name'] || 'session'
  md5 = Digest::MD5.hexdigest(id)
  @store_dir = File.join(dir, prefix + md5)
  FileUtils.mkdir_p(@store_dir)
  @store_path = File.join(@store_dir, name)
  @store_path.untaint
  if (File.exist? "#{@store_path}.lock") then
    @hash = nil
  else
    unless (session.new_session) then
      raise CGI::Session::NoSession, 'uninitialized session'
    end
    @hash = {}
  end
  @store = Higgs::Store.new(@store_path, options)
end

Instance Method Details

#closeObject



56
57
58
59
60
61
62
63
# File 'lib/cgi/session/higgs.rb', line 56

def close
  r = nil
  unless (@store.shutdown?) then
    r = update
    @store.shutdown
  end
  r
end

#deleteObject



65
66
67
68
69
# File 'lib/cgi/session/higgs.rb', line 65

def delete
  @store.shutdown unless @store.shutdown?
  FileUtils.rm_rf(@store_dir)
  nil
end

#restoreObject



41
42
43
44
45
46
47
48
# File 'lib/cgi/session/higgs.rb', line 41

def restore
  unless (@hash) then
    @store.transaction{|tx|
      @hash = tx[:hash] || {}
    }
  end
  @hash
end

#updateObject



50
51
52
53
54
# File 'lib/cgi/session/higgs.rb', line 50

def update
  @store.transaction{|tx|
    tx[:hash] = @hash
  }
end