Permalink
Browse files

Make data writer private. Marshal/unmarshal handle nil.

git-svn-id: http://svn-commit.rubyonrails.org/rails/trunk@3108 5ecf4fe2-1ee6-0310-87b1-e25e094e27de
  • Loading branch information...
1 parent c7bc10b commit 63b792162bd999c873a4c66936ac36ac5943d53b @jeremy jeremy committed Nov 20, 2005
Showing with 8 additions and 8 deletions.
  1. +8 −8 actionpack/lib/action_controller/session/active_record_store.rb
@@ -80,8 +80,8 @@ def find_by_session_id(session_id)
find_by_session_id(session_id)
end
- def marshal(data) Base64.encode64(Marshal.dump(data)) end
- def unmarshal(data) Marshal.load(Base64.decode64(data)) end
+ def marshal(data) Base64.encode64(Marshal.dump(data)) if data end
+ def unmarshal(data) Marshal.load(Base64.decode64(data)) if data end
def create_table!
connection.execute <<-end_sql
@@ -117,14 +117,14 @@ def self.find_by_session_id(session_id)
end
end
- attr_writer :data
-
# Lazy-unmarshal session state.
def data
- @data ||= self.class.unmarshal(read_attribute(@@data_column_name))
+ @data ||= self.class.unmarshal(read_attribute(@@data_column_name)) || {}
end
private
+ attr_writer :data
+
def marshal_data!
write_attribute(@@data_column_name, self.class.marshal(self.data))
end
@@ -187,8 +187,8 @@ def find_by_session_id(session_id)
end
end
- def marshal(data) Base64.encode64(Marshal.dump(data)) end
- def unmarshal(data) Marshal.load(Base64.decode64(data)) end
+ def marshal(data) Base64.encode64(Marshal.dump(data)) if data end
+ def unmarshal(data) Marshal.load(Base64.decode64(data)) if data end
def create_table!
@@connection.execute <<-end_sql
@@ -224,7 +224,7 @@ def new_record?
def data
unless @data
if @marshaled_data
- @data, @marshaled_data = self.class.unmarshal(@marshaled_data), nil
+ @data, @marshaled_data = self.class.unmarshal(@marshaled_data) || {}, nil
else
@data = {}
end

0 comments on commit 63b7921

Please sign in to comment.