Skip to content

Instantly share code, notes, and snippets.

Embed
What would you like to do?
Marshal serializer for ActiveRecord 4.
module Coders
class Marshal
attr_reader :klass
def initialize(klass)
@klass = klass
end
def load(data)
if data
::Marshal.load(data)
else
klass.new
end
rescue ArgumentError
klass.new
end
def dump(data)
::Marshal.dump(data)
end
end
end
class User < ActiveRecord::Base
serialize :settings, Coders::Marshal.new(Hash)
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment
You can’t perform that action at this time.