lib/supermodel/marshal.rb in supermodel-0.1.2 vs lib/supermodel/marshal.rb in supermodel-0.1.3
- old
+ new
@@ -20,18 +20,21 @@
return unless File.exist?(path)
data = []
File.open(path, "rb") do |file|
begin
data = ::Marshal.load(file)
- rescue
+ rescue => e
+ if defined?(Bowline)
+ Bowline::Logging.log_error(e)
+ end
# Lots of errors can occur during
# marshaling - such as EOF etc
return false
end
end
data.each do |klass, records|
- klass.marshal_records(records)
+ klass.marshal_records = records
end
true
end
def dump
@@ -41,10 +44,11 @@
data = klasses.inject({}) {|hash, klass|
hash[klass] = klass.marshal_records
hash
}
::Marshal.dump(data, tmp_file)
+ tmp_file.close
# Atomic serialization - so we never corrupt the db
FileUtils.mv(tmp_file.path, path)
true
end
@@ -55,23 +59,33 @@
base.extend ClassMethods
Marshal.klasses << base
end
def marshal_dump
- serializable_hash
+ serializable_hash(self.class.marshal)
end
def marshal_load(atts)
# Can't call load, since class
# isn't setup properly
- @attributes = atts
+ @attributes = atts.with_indifferent_access
+ @changed_attributes = {}
end
module ClassMethods
- def marshal_records(records = nil)
- @records = records if records
- @records
+ def marshal(options = nil)
+ @marshal = options if options
+ @marshal ||= {}
end
+ alias_method :marshal=, :marshal
+
+ def marshal_records=(records)
+ @records = records
+ end
+
+ def marshal_records
+ @records
+ end
end
end
end
end
\ No newline at end of file