Class: ActionDispatch::Session::AbstractStore

Inherits:
Object
  • Object
show all
Defined in:
actionpack/lib/action_dispatch/middleware/session/abstract_store.rb

Constant Summary

Instance Method Summary (collapse)

Constructor Details

- (AbstractStore) initialize(app, options = {})

A new instance of AbstractStore



139
140
141
142
143
144
145
# File 'actionpack/lib/action_dispatch/middleware/session/abstract_store.rb', line 139

def initialize(app, options = {})
  @app = app
  @default_options = DEFAULT_OPTIONS.merge(options)
  @key = @default_options.delete(:key).freeze
  @cookie_only = @default_options.delete(:cookie_only)
  ensure_session_key!
end

Instance Method Details

- (Object) call(env)



147
148
149
150
151
152
153
154
155
156
157
158
159
160
161
162
163
164
165
166
167
168
169
170
171
172
173
# File 'actionpack/lib/action_dispatch/middleware/session/abstract_store.rb', line 147

def call(env)
  prepare!(env)
  response = @app.call(env)

  session_data = env[ENV_SESSION_KEY]
  options = env[ENV_SESSION_OPTIONS_KEY]

  if !session_data.is_a?(AbstractStore::SessionHash) || session_data.loaded? || options[:expire_after]
    session_data.send(:load!) if session_data.is_a?(AbstractStore::SessionHash) && !session_data.loaded?

    sid = options[:id] || generate_sid
    session_data = session_data.to_hash

    value = set_session(env, sid, session_data)
    return response unless value

    cookie = { :value => value }
    unless options[:expire_after].nil?
      cookie[:expires] = Time.now + options.delete(:expire_after)
    end

    request = ActionDispatch::Request.new(env)
    set_cookie(request, cookie.merge!(options))
  end

  response
end