Skip to content

Instantly share code, notes, and snippets.

@krisleech
Created June 6, 2011 14:13
Show Gist options
  • Star 1 You must be signed in to star a gist
  • Fork 0 You must be signed in to fork a gist
  • Save krisleech/1010338 to your computer and use it in GitHub Desktop.
Save krisleech/1010338 to your computer and use it in GitHub Desktop.
# Untested, mind dump
class Document < ActiveRecord::Base
include Virtus
before_save :dump_attributes
after_initialize :load_attributes
private
def dump_attributes
attributes_store = {}
self.attributes.collect { | attribute, meta | attributes_store[attribute] = self.send(attribute) }
write_attribute(:attributes_store, Marshall.dump(attributes_store))
end
def load_attributes
Marshall.load(read_attribute(attributes_store)).each do | attribute, value |
self.send(attribute) = value
end
end
end
class Event < Document
attribute :starts_at_date, Date
attribute :capacity, Integer
end
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment