Skip to content

Instantly share code, notes, and snippets.

@faust45
Created April 1, 2010 09:09
Show Gist options
  • Star 0 You must be signed in to star a gist
  • Fork 1 You must be signed in to fork a gist
  • Save faust45/351578 to your computer and use it in GitHub Desktop.
Save faust45/351578 to your computer and use it in GitHub Desktop.
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