Class: Rack::Session::File::YAML::Transaction

Inherits:
Abstract::Transaction show all
Defined in:
lib/rack/session/file/yaml.rb

Instance Method Summary collapse

Methods inherited from Abstract::Transaction

#find_session, #save_session, #with_lock

Constructor Details

#initialize(env, options = {}) ⇒ Transaction

Returns a new instance of Transaction.



22
23
24
25
# File 'lib/rack/session/file/yaml.rb', line 22

def initialize(env, options = {})
  super
  @yaml_options = options[:yaml] || {}
end

Instance Method Details

#delete_session(sid) ⇒ Object



55
56
57
58
59
60
61
62
63
# File 'lib/rack/session/file/yaml.rb', line 55

def delete_session(sid)
  begin
    filename = store_for_sid(sid).path
    if ::File.exists?(filename)
      ::File.unlink(filename)
    end
  rescue InvalidSessionIDError
  end
end

#expire_sessions(time) ⇒ Object



65
66
67
# File 'lib/rack/session/file/yaml.rb', line 65

def expire_sessions(time)
  # TODO
end

#load_session(sid) ⇒ Object



37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
# File 'lib/rack/session/file/yaml.rb', line 37

def load_session(sid)
  ensure_storage_accessible()

  data = {}
  begin
    store_for_sid(sid).transaction(true) do |db|
      db.roots.each do |key|
        data[key] = db[key]
      end
    end
  rescue InvalidSessionIDError
    return nil
  rescue (::Psych::SyntaxError rescue nil), (::Syck::Error rescue nil), (::Syck::TypeError rescue nil)
    return nil
  end
  return data
end

#store_session(sid, data) ⇒ Object



27
28
29
30
31
32
33
34
35
# File 'lib/rack/session/file/yaml.rb', line 27

def store_session(sid, data)
  ensure_storage_accessible()

  store_for_sid(sid).transaction do |db|
    data.keys.each do |key|
      db[key] = data[key]
    end
  end
end