diff options
author | Jeremy Kemper <jeremy@bitsweat.net> | 2005-07-04 21:26:54 +0000 |
---|---|---|
committer | Jeremy Kemper <jeremy@bitsweat.net> | 2005-07-04 21:26:54 +0000 |
commit | 9ad1f4998546384254aadd19bfa08024c77539b9 (patch) | |
tree | e002247e459910b924bed65ff2afd372bfe8180d /actionpack/lib | |
parent | 509bf538894531f4329810f0489446f200d60f12 (diff) | |
download | rails-9ad1f4998546384254aadd19bfa08024c77539b9.tar.gz rails-9ad1f4998546384254aadd19bfa08024c77539b9.tar.bz2 rails-9ad1f4998546384254aadd19bfa08024c77539b9.zip |
r2810@asus: jeremy | 2005-07-04 19:29:54 -0700
correct marshaling and fingerprinting logic
git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1682 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
Diffstat (limited to 'actionpack/lib')
-rw-r--r-- | actionpack/lib/action_controller/session/active_record_store.rb | 31 |
1 files changed, 23 insertions, 8 deletions
diff --git a/actionpack/lib/action_controller/session/active_record_store.rb b/actionpack/lib/action_controller/session/active_record_store.rb index 7d9bcabc8c..d539fd2a95 100644 --- a/actionpack/lib/action_controller/session/active_record_store.rb +++ b/actionpack/lib/action_controller/session/active_record_store.rb @@ -85,12 +85,18 @@ class CGI end end - # Lazy-unmarshal session state. + # Lazy-unmarshal session state. Take a fingerprint so we can detect + # whether to save changes later. def data unless @data - marshaled_data = read_attribute('data') - @fingerprint = self.class.fingerprint(marshaled_data) - @data = self.class.unmarshal(marshaled_data) + case @data = read_attribute('data') + when String + @fingerprint = self.class.fingerprint(@data) + @data = self.class.unmarshal(@data) + when nil + @data = {} + @fingerprint = nil + end end @data end @@ -172,15 +178,24 @@ class CGI # We need to handle a normal data attribute in case of a new record. def initialize(attributes) @session_id, @data, @marshaled_data = attributes[:session_id], attributes[:data], attributes[:marshaled_data] - @new_record = !@marshaled_data.nil? + @new_record = @marshaled_data.nil? + end + + def new_record? + @new_record end # Lazy-unmarshal session state. Take a fingerprint so we can detect # whether to save changes later. def data - if @marshaled_data - @fingerprint = self.class.fingerprint(@marshaled_data) - @data, @marshaled_data = self.class.unmarshal(@marshaled_data), nil + unless @data + if @marshaled_data + @fingerprint = self.class.fingerprint(@marshaled_data) + @data, @marshaled_data = self.class.unmarshal(@marshaled_data), nil + else + @data = {} + @fingerprint = nil + end end @data end |