Created
April 1, 2010 09:09
-
-
Save faust45/351578 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
class BaseModel < CouchRest::ExtendedDocument | |
include ActiveModel::Dirty | |
use_database DB | |
def initialize(passed_keys={}, options={}) | |
super(passed_keys, options) | |
@changed_attributes = {} | |
end | |
class <<self | |
def create_property_setter(property) | |
property_name = property.name | |
class_eval <<-EOS | |
def #{property_name}=(value) | |
self.send('#{property_name}_will_change!') | |
self['#{property_name}'] = value | |
cast_property_by_name('#{property_name}') | |
end | |
EOS | |
if property.alias | |
class_eval <<-EOS | |
alias #{property.alias.to_sym}= #{property_name.to_sym}= | |
EOS | |
end | |
end | |
end | |
def attributes | |
self.to_hash | |
end | |
end |
Sign up for free
to join this conversation on GitHub.
Already have an account?
Sign in to comment