Created
June 6, 2011 14:13
-
-
Save krisleech/1010338 to your computer and use it in GitHub Desktop.
This file contains bidirectional Unicode text that may be interpreted or compiled differently than what appears below. To review, open the file in an editor that reveals hidden Unicode characters.
Learn more about bidirectional Unicode characters
# 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