Ruby on Rails | Screencasts | Download | Documentation | Weblog | Community | Source

Changeset 3108

Show
Ignore:
Timestamp:
11/20/05 08:15:51 (3 years ago)
Author:
bitsweat
Message:

Make data writer private. Marshal/unmarshal handle nil.

Files:

Legend:

Unmodified
Added
Removed
Modified
Copied
Moved
  • trunk/actionpack/lib/action_controller/session/active_record_store.rb

    r3107 r3108  
    8181          end 
    8282 
    83           def marshal(data)     Base64.encode64(Marshal.dump(data)) end 
    84           def unmarshal(data)   Marshal.load(Base64.decode64(data)) end 
     83          def marshal(data)   Base64.encode64(Marshal.dump(data)) if data end 
     84          def unmarshal(data) Marshal.load(Base64.decode64(data)) if data end 
    8585 
    8686          def create_table! 
     
    118118        end 
    119119 
    120         attr_writer :data 
    121  
    122120        # Lazy-unmarshal session state. 
    123121        def data 
    124           @data ||= self.class.unmarshal(read_attribute(@@data_column_name)) 
     122          @data ||= self.class.unmarshal(read_attribute(@@data_column_name)) || {} 
    125123        end 
    126124 
    127125        private 
     126          attr_writer :data 
     127 
    128128          def marshal_data! 
    129129            write_attribute(@@data_column_name, self.class.marshal(self.data)) 
     
    188188          end 
    189189 
    190           def marshal(data)     Base64.encode64(Marshal.dump(data)) end 
    191           def unmarshal(data)   Marshal.load(Base64.decode64(data)) end 
     190          def marshal(data)   Base64.encode64(Marshal.dump(data)) if data end 
     191          def unmarshal(data) Marshal.load(Base64.decode64(data)) if data end 
    192192 
    193193          def create_table! 
     
    225225          unless @data 
    226226            if @marshaled_data 
    227               @data, @marshaled_data = self.class.unmarshal(@marshaled_data), nil 
     227              @data, @marshaled_data = self.class.unmarshal(@marshaled_data) || {}, nil 
    228228            else 
    229229              @data = {}