Skip to content

Instantly share code, notes, and snippets.

@mrrooijen
Last active August 29, 2015 13:57
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save mrrooijen/9587170 to your computer and use it in GitHub Desktop.
Save mrrooijen/9587170 to your computer and use it in GitHub Desktop.
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