From 3692ca5ce7a0dbb11c4001891488905c53fbc5e5 Mon Sep 17 00:00:00 2001 From: Aaron Patterson Date: Sat, 13 Jun 2015 14:12:44 -0700 Subject: don't hold a reference to `env` in the options object I want to decouple Rails from the rack ENV as much as possible. We should try to keep as few references to the env as possible --- actionpack/lib/action_dispatch/request/session.rb | 24 +++++++++++------------ 1 file changed, 11 insertions(+), 13 deletions(-) (limited to 'actionpack') diff --git a/actionpack/lib/action_dispatch/request/session.rb b/actionpack/lib/action_dispatch/request/session.rb index 773d41de88..a8a3cd20b9 100644 --- a/actionpack/lib/action_dispatch/request/session.rb +++ b/actionpack/lib/action_dispatch/request/session.rb @@ -17,7 +17,7 @@ module ActionDispatch session.merge! session_was if session_was set(env, session) - Options.set(env, Request::Session::Options.new(store, env, default_options)) + Options.set(env, Request::Session::Options.new(store, default_options)) session end @@ -38,20 +38,19 @@ module ActionDispatch env[ENV_SESSION_OPTIONS_KEY] end - def initialize(by, env, default_options) + def initialize(by, default_options) @by = by - @env = env @delegate = default_options.dup end def [](key) - if key == :id - @delegate.fetch(key) { - @delegate[:id] = @by.send(:extract_session_id, @env) - } - else - @delegate[key] - end + @delegate[key] + end + + def id(env) + @delegate.fetch(:id) { + @by.send(:extract_session_id, env) + } end def []=(k,v); @delegate[k] = v; end @@ -68,7 +67,7 @@ module ActionDispatch end def id - options[:id] + options.id(@env) end def options @@ -78,8 +77,7 @@ module ActionDispatch def destroy clear options = self.options || {} - new_sid = @by.send(:destroy_session, @env, options[:id], options) - options[:id] = new_sid # Reset session id with a new value or nil + @by.send(:destroy_session, @env, options.id(@env), options) # Load the new sid to be written with the response @loaded = false -- cgit v1.2.3