Skip to content

Commit

Permalink
r2810@asus: jeremy | 2005-07-04 19:29:54 -0700
Browse files Browse the repository at this point in the history
 correct marshaling and fingerprinting logic


git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@1682 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information
jeremy committed Jul 4, 2005
1 parent 509bf53 commit 9ad1f49
Showing 1 changed file with 23 additions and 8 deletions.
31 changes: 23 additions & 8 deletions actionpack/lib/action_controller/session/active_record_store.rb
Expand Up @@ -85,12 +85,18 @@ def drop_table!
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
Expand Down Expand Up @@ -172,15 +178,24 @@ def drop_table!
# 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
Expand Down

0 comments on commit 9ad1f49

Please sign in to comment.