aboutsummaryrefslogtreecommitdiffstats
path: root/activerecord/lib/active_record/base.rb
diff options
context:
space:
mode:
authorJon Leighton <j@jonathanleighton.com>2011-01-06 17:01:24 +0000
committerAaron Patterson <aaron.patterson@gmail.com>2011-01-07 15:03:15 -0800
commit441118458d57011ee1b1f1dcfea558de462c6da9 (patch)
tree669afc968f481f20c715d2258bc6dcc733b154c8 /activerecord/lib/active_record/base.rb
parent2efd780dcb91b9df5eb05ae8b4837602a33c16fc (diff)
downloadrails-441118458d57011ee1b1f1dcfea558de462c6da9.tar.gz
rails-441118458d57011ee1b1f1dcfea558de462c6da9.tar.bz2
rails-441118458d57011ee1b1f1dcfea558de462c6da9.zip
Use encode_with for marshalling
Diffstat (limited to 'activerecord/lib/active_record/base.rb')
-rw-r--r--activerecord/lib/active_record/base.rb20
1 files changed, 20 insertions, 0 deletions
diff --git a/activerecord/lib/active_record/base.rb b/activerecord/lib/active_record/base.rb
index 632c7aff4a..1079094bbf 100644
--- a/activerecord/lib/active_record/base.rb
+++ b/activerecord/lib/active_record/base.rb
@@ -870,6 +870,16 @@ module ActiveRecord #:nodoc:
reset_scoped_methods
end
+ # Specifies how the record is loaded by +Marshal+.
+ #
+ # +_load+ sets an instance variable for each key in the hash it takes as input.
+ # Override this method if you require more complex marshalling.
+ def _load(data)
+ record = allocate
+ record.init_with(Marshal.load(data))
+ record
+ end
+
private
def relation #:nodoc:
@@ -1425,6 +1435,16 @@ MSG
_run_initialize_callbacks
end
+ # Specifies how the record is dumped by +Marshal+.
+ #
+ # +_dump+ emits a marshalled hash which has been passed to +encode_with+. Override this
+ # method if you require more complex marshalling.
+ def _dump(level)
+ dump = {}
+ encode_with(dump)
+ Marshal.dump(dump)
+ end
+
# Returns a String, which Action Pack uses for constructing an URL to this
# object. The default implementation returns this record's id as a String,
# or nil if this record's unsaved.