Class: Rack::Session::File::Abstract

Inherits:
Abstract::ID
  • Object
show all
Includes:
ActionDispatch::Session::Compatibility, ActionDispatch::Session::StaleSessionCheck
Defined in:
lib/rails-session-file.rb,
lib/rack/session/file/abstract.rb

Direct Known Subclasses

Marshal, PStore, YAML

Defined Under Namespace

Classes: Transaction

Constant Summary collapse

DEFAULT_OPTIONS =
Rack::Session::Abstract::ID::DEFAULT_OPTIONS.merge({
  :storage             => Dir.tmpdir,
  :clear_expired_after => 30 * 60,
})

Instance Method Summary collapse

Constructor Details

#initialize(app, options = {}) ⇒ Abstract

Returns a new instance of Abstract.



16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/rack/session/file/abstract.rb', line 16

def initialize(app, options = {})
  super

  @storage               = @default_options.delete(:storage)
  @recheck_expire_period = @default_options.delete(:clear_expired_after).to_i

  @next_expire_period = nil

  @transaction_options = {
    :storage => @storage,
  }
end

Instance Method Details

#destroy_session(env, sid, options) ⇒ Object



63
64
65
66
67
68
# File 'lib/rack/session/file/abstract.rb', line 63

def destroy_session(env, sid, options)
  new_transaction(env).with_lock do |transaction|
    transaction.delete_session(sid)
    new_sid(env)  unless options[:drop]
  end
end

#get_session(env, sid) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
# File 'lib/rack/session/file/abstract.rb', line 29

def get_session(env, sid)
  new_transaction(env).with_lock do |transaction|
    session = find_session(env, sid) if sid
    unless sid and session
      env['rack.errors'].puts("Session '#{sid}' not found, initializing...")  if $VERBOSE and not sid.nil?
      session = {}
      sid = new_sid(env)
      transaction.save_session(sid)
    end
    session.instance_variable_set('@old', {}.merge(session))
    session.instance_variable_set('@sid', sid)
    return [sid, session]
  end
end

#set_session(env, sid, new_session, options) ⇒ Object



44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
# File 'lib/rack/session/file/abstract.rb', line 44

def set_session(env, sid, new_session, options)
  new_transaction(env).with_lock do |transaction|
    expires = Time.now + options[:expire_after]  if ! options[:expire_after].nil?
    session = find_session(env, sid) || {}

    if options[:renew] or options[:drop]
      transaction.delete_session(sid)
      return false  if options[:drop]
      sid = new_sid(env)
      #transaction.save_session(sid, session, expires)
    end

    old_session = new_session.instance_variable_defined?('@old') ? new_session.instance_variable_get('@old') : {}
    session = merge_sessions(sid, old_session, new_session, session)
    transaction.save_session(sid, session, expires)
    return sid
  end
end