Skip to content

Instantly share code, notes, and snippets.

@JamesHayton
Forked from faust45/gist:351578
Created April 25, 2010 12:24
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 JamesHayton/378368 to your computer and use it in GitHub Desktop.
Save JamesHayton/378368 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