Parent

Class Index [+]

Quicksearch

ActionDispatch::Session::AbstractStore

Constants

ENV_SESSION_KEY
ENV_SESSION_OPTIONS_KEY
DEFAULT_OPTIONS

Public Class Methods

new(app, options = {}) click to toggle source
     # File lib/action_dispatch/middleware/session/abstract_store.rb, line 139
139:       def initialize(app, options = {})
140:         @app = app
141:         @default_options = DEFAULT_OPTIONS.merge(options)
142:         @key = @default_options.delete(:key).freeze
143:         @cookie_only = @default_options.delete(:cookie_only)
144:         ensure_session_key!
145:       end

Public Instance Methods

call(env) click to toggle source
     # File lib/action_dispatch/middleware/session/abstract_store.rb, line 147
147:       def call(env)
148:         prepare!(env)
149:         response = @app.call(env)
150: 
151:         session_data = env[ENV_SESSION_KEY]
152:         options = env[ENV_SESSION_OPTIONS_KEY]
153: 
154:         if !session_data.is_a?(AbstractStore::SessionHash) || session_data.loaded? || options[:expire_after]
155:           session_data.send(:load!) if session_data.is_a?(AbstractStore::SessionHash) && !session_data.loaded?
156: 
157:           sid = options[:id] || generate_sid
158:           session_data = session_data.to_hash
159: 
160:           value = set_session(env, sid, session_data)
161:           return response unless value
162: 
163:           cookie = { :value => value }
164:           unless options[:expire_after].nil?
165:             cookie[:expires] = Time.now + options.delete(:expire_after)
166:           end
167: 
168:           request = ActionDispatch::Request.new(env)
169:           set_cookie(request, cookie.merge!(options))
170:         end
171: 
172:         response
173:       end

Private Instance Methods

current_session_id(env) click to toggle source
     # File lib/action_dispatch/middleware/session/abstract_store.rb, line 209
209:         def current_session_id(env)
210:           env[ENV_SESSION_OPTIONS_KEY][:id]
211:         end
destroy(env) click to toggle source
     # File lib/action_dispatch/middleware/session/abstract_store.rb, line 251
251:         def destroy(env)
252:           raise '#destroy needs to be implemented.'
253:         end
ensure_session_key!() click to toggle source
     # File lib/action_dispatch/middleware/session/abstract_store.rb, line 213
213:         def ensure_session_key!
214:           if @key.blank?
215:             raise ArgumentError, 'A key is required to write a ' +
216:               'cookie containing the session data. Use ' +
217:               'config.session_store SESSION_STORE, { :key => ' +
218:               '"_myapp_session" } in config/application.rb'
219:           end
220:         end
exists?(env) click to toggle source
     # File lib/action_dispatch/middleware/session/abstract_store.rb, line 238
238:         def exists?(env)
239:           current_session_id(env).present?
240:         end
extract_session_id(env) click to toggle source
     # File lib/action_dispatch/middleware/session/abstract_store.rb, line 200
200:         def extract_session_id(env)
201:           stale_session_check! do
202:             request = ActionDispatch::Request.new(env)
203:             sid = request.cookies[@key]
204:             sid ||= request.params[@key] unless @cookie_only
205:             sid
206:           end
207:         end
generate_sid() click to toggle source
     # File lib/action_dispatch/middleware/session/abstract_store.rb, line 182
182:         def generate_sid
183:           ActiveSupport::SecureRandom.hex(16)
184:         end
get_session(env, sid) click to toggle source
     # File lib/action_dispatch/middleware/session/abstract_store.rb, line 242
242:         def get_session(env, sid)
243:           raise '#get_session needs to be implemented.'
244:         end
load_session(env) click to toggle source
     # File lib/action_dispatch/middleware/session/abstract_store.rb, line 192
192:         def load_session(env)
193:           stale_session_check! do
194:             sid = current_session_id(env)
195:             sid, session = get_session(env, sid)
196:             [sid, session]
197:           end
198:         end
prepare!(env) click to toggle source
     # File lib/action_dispatch/middleware/session/abstract_store.rb, line 177
177:         def prepare!(env)
178:           env[ENV_SESSION_KEY] = SessionHash.new(self, env)
179:           env[ENV_SESSION_OPTIONS_KEY] = OptionsHash.new(self, env, @default_options)
180:         end
set_session(env, sid, session_data) click to toggle source
     # File lib/action_dispatch/middleware/session/abstract_store.rb, line 246
246:         def set_session(env, sid, session_data)
247:           raise '#set_session needs to be implemented and should return ' <<
248:             'the value to be stored in the cookie (usually the sid)'
249:         end
stale_session_check!() click to toggle source
     # File lib/action_dispatch/middleware/session/abstract_store.rb, line 222
222:         def stale_session_check!
223:           yield
224:         rescue ArgumentError => argument_error
225:           if argument_error.message =~ %{undefined class/module ([\w:]*\w)}
226:             begin
227:               # Note that the regexp does not allow $1 to end with a ':'
228:               $1.constantize
229:             rescue LoadError, NameError => const_error
230:               raise ActionDispatch::Session::SessionRestoreError, "Session contains objects whose class definition isn't available.\nRemember to require the classes for all objects kept in the session.\n(Original exception: #{const_error.message} [#{const_error.class}])\n"
231:             end
232:             retry
233:           else
234:             raise
235:           end
236:         end

Disabled; run with --debug to generate this.

[Validate]

Generated with the Darkfish Rdoc Generator 1.1.6.