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

Inherits:
Object
  • Object
show all
Defined in:
lib/rack/session/file/abstract.rb

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Transaction.



115
116
117
118
119
# File 'lib/rack/session/file/abstract.rb', line 115

def initialize(env, options = {})
  @env = env
  @storage = options[:storage]
  @mutex = Mutex.new if want_thread_safe?
end

Instance Method Details

#delete_session(sid) ⇒ Object



153
154
155
# File 'lib/rack/session/file/abstract.rb', line 153

def delete_session(sid)
  raise '#delete_session not implemented'
end

#expire_sessions(time) ⇒ Object



157
158
159
# File 'lib/rack/session/file/abstract.rb', line 157

def expire_sessions(time)
  raise '#expire_sessions not implemented'
end

#find_session(sid) ⇒ Object



130
131
132
133
134
135
136
137
138
139
# File 'lib/rack/session/file/abstract.rb', line 130

def find_session(sid)
  session = load_session(sid)

  if session && session[:expires] != nil && session[:expires] < Time.now
    delete_session(sid)
    session = nil
  end

  return session ? session[:data] : nil
end

#load_session(sid) ⇒ Object



149
150
151
# File 'lib/rack/session/file/abstract.rb', line 149

def load_session(sid)
  raise '#load_session not implemented'
end

#save_session(sid, session = {}, expires = nil) ⇒ Object



141
142
143
# File 'lib/rack/session/file/abstract.rb', line 141

def save_session(sid, session = {}, expires = nil)
  store_session(sid, { :data => session, :expires => expires })
end

#store_session(sid, data) ⇒ Object



145
146
147
# File 'lib/rack/session/file/abstract.rb', line 145

def store_session(sid, data)
  raise '#store_session not implemented'
end

#with_lockObject



121
122
123
124
125
126
127
128
# File 'lib/rack/session/file/abstract.rb', line 121

def with_lock
  @mutex.lock if want_thread_safe?
  begin
    yield(self)
  ensure
    @mutex.unlock if want_thread_safe?
  end
end