diff options
author | Aaron Patterson <aaron.patterson@gmail.com> | 2012-05-02 15:14:47 -0700 |
---|---|---|
committer | Aaron Patterson <aaron.patterson@gmail.com> | 2012-05-02 15:14:47 -0700 |
commit | 1ef527f9f96dd6cb9d6f0a93886a28838885513e (patch) | |
tree | f58baa4448554ae05bc7bd1e62f920f57851642f /actionpack/lib/action_dispatch | |
parent | 385afd47dab645f97b79c25419ec5e1f5b52babe (diff) | |
download | rails-1ef527f9f96dd6cb9d6f0a93886a28838885513e.tar.gz rails-1ef527f9f96dd6cb9d6f0a93886a28838885513e.tar.bz2 rails-1ef527f9f96dd6cb9d6f0a93886a28838885513e.zip |
converted session hash to delegation
Diffstat (limited to 'actionpack/lib/action_dispatch')
-rw-r--r-- | actionpack/lib/action_dispatch/middleware/session/abstract_store.rb | 40 |
1 files changed, 19 insertions, 21 deletions
diff --git a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb index e9f5a9aebe..48f1006e5e 100644 --- a/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb +++ b/actionpack/lib/action_dispatch/middleware/session/abstract_store.rb @@ -93,7 +93,7 @@ module ActionDispatch class Request # SessionHash is responsible to lazily load the session from store. - class Session < Hash + class Session # :nodoc: ENV_SESSION_KEY = Rack::Session::Abstract::ENV_SESSION_KEY # :nodoc: ENV_SESSION_OPTIONS_KEY = Rack::Session::Abstract::ENV_SESSION_OPTIONS_KEY # :nodoc: @@ -119,66 +119,64 @@ module ActionDispatch def values_at(*args); @delegate.values_at(*args); end end + def initialize(by, env) + @by = by + @env = env + @delegate = {} + @loaded = false + end + def destroy clear - options = @env[Rack::Session::Abstract::ENV_SESSION_OPTIONS_KEY] if @env + options = @env[ENV_SESSION_OPTIONS_KEY] if @env options ||= {} @by.send(:destroy_session, @env, options[:id], options) if @by options[:id] = nil @loaded = false end - def initialize(by, env) - super() - @by = by - @env = env - @loaded = false - end - def [](key) load_for_read! - super(key.to_s) + @delegate[key.to_s] end def has_key?(key) load_for_read! - super(key.to_s) + @delegate.key?(key.to_s) end alias :key? :has_key? alias :include? :has_key? def []=(key, value) load_for_write! - super(key.to_s, value) + @delegate[key.to_s] = value end def clear load_for_write! - super + @delegate.clear end def to_hash load_for_read! - h = {}.replace(self) - h.delete_if { |k,v| v.nil? } - h + @delegate.dup.delete_if { |_,v| v.nil? } end def update(hash) load_for_write! - super(stringify_keys(hash)) + @delegate.update stringify_keys(hash) end def delete(key) load_for_write! - super(key.to_s) + @delegate.delete key.to_s end def inspect if loaded? super else - "#<#{self.class}:0x#{self.object_id.to_s(16)} not yet loaded>" + "#<#{self.class}:0x#{(object_id << 1).to_s(16)} not yet loaded>" end end @@ -193,7 +191,7 @@ module ActionDispatch def empty? load_for_read! - super + @delegate.empty? end private @@ -209,7 +207,7 @@ module ActionDispatch def load! id, session = @by.send(:load_session, @env) @env[ENV_SESSION_OPTIONS_KEY][:id] = id - replace(stringify_keys(session)) + @delegate.replace(stringify_keys(session)) @loaded = true end |