Marshalize
This Rails plugin provides serialization using Marshal in the same way Rails provides builtin serialization using YAML. In a model, just do
class Robot < ActiveRecord::Base
marshalize :features
end
and your app will automagically handle the features
attribute using Marshal, dumping when saving to the database, loading when fetching from it.
You can register any kind object (not just arrays and hashes…). Be aware that Marshal defines a binary format, which may change in incoming Ruby releases and is currently not portable outside the Ruby scripting world. For a portable yet slower alternatives, you may try JSON or YML serializers.
Example
class Robot < ActiveRecord::Base
marshalize :parameters # The "parameters" attribute will be saved as binary data
marshalize :features, RobotFeature # You can define what kind of object is to be marshalized
# An error will be raised if another class is provided for
# this attribute
serialize :status, Array # Marshalization plays well with YAML classic serialization
end
Installation
as a plugin:
In your Rails application root directory:
script/plugin install git://github.com/chikamichi/marshalize.git
as a gem:
Not yet!
No rake task needed.
TODO
-
super
stuff -
manage blobs, not just text field (buffer limitations)
-
rake tasks to manage marshalized data recovering in case Marshal went astray (say, a new version breaking things down)
License
Released under the WTFPL (sam.zoy.org/wtfpl/COPYING)