Class: Rack::Session::File::Abstract
- Inherits:
-
Abstract::ID
- Object
- Abstract::ID
- Rack::Session::File::Abstract
- Includes:
- ActionDispatch::Session::Compatibility, ActionDispatch::Session::StaleSessionCheck
- Defined in:
- lib/rails-session-file.rb,
lib/rack/session/file/abstract.rb
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
- #destroy_session(env, sid, options) ⇒ Object
- #get_session(env, sid) ⇒ Object
-
#initialize(app, options = {}) ⇒ Abstract
constructor
A new instance of Abstract.
- #set_session(env, sid, new_session, options) ⇒ Object
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, = {}) 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, ) new_transaction(env).with_lock do |transaction| transaction.delete_session(sid) new_sid(env) unless [: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, ) new_transaction(env).with_lock do |transaction| expires = Time.now + [:expire_after] if ! [:expire_after].nil? session = find_session(env, sid) || {} if [:renew] or [:drop] transaction.delete_session(sid) return false if [: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 |