lib/madeleine.rb in madeleine-0.8.0.pre vs lib/madeleine.rb in madeleine-0.8.0
- old
+ new
@@ -1,10 +1,10 @@
#
# Madeleine - Ruby Object Prevalence
#
# Author:: Anders Bengtsson <ndrsbngtssn@yahoo.se>
-# Copyright:: Copyright (c) 2003-2006
+# Copyright:: Copyright (c) 2003-2012
#
# Usage:
#
# require 'madeleine'
#
@@ -146,10 +146,15 @@
def verify_command_sane(command)
unless command.respond_to?(:execute)
raise InvalidCommandException.new("Commands must have an 'execute' method")
end
+ if command.respond_to?(:marshal_dump)
+ unless command.respond_to?(:marshal_load)
+ raise InvalidCommandException.new("A Command with custom marshalling (mashal_dump()) must also define marshal_load()")
+ end
+ end
end
end
class InvalidCommandException < Exception
end
@@ -280,10 +285,13 @@
def close
@file.close
end
def store(command)
- Marshal.dump(command, @file)
+ # Dumping to intermediate String instead of to IO directly, to make sure
+ # all of the marshalling worked before we write anything to the log.
+ data = Marshal.dump(command)
+ @file.write(data)
@file.flush
@file.fsync
end
def self.highest_log(directory_name, file_service)