Started on the ExtendedDocument class with features moved to mixins.

Properties got added, they define getters, setters and aliases.
They will also be the base of the new validation system.
This commit is contained in:
Matt Aimonetti 2009-01-29 18:45:01 -08:00 committed by Chris Anderson
parent 83d7341553
commit d64fa45cf0
2 changed files with 9 additions and 3 deletions

View file

@ -35,6 +35,12 @@ module CouchRest
first_instance.empty? ? nil : first_instance.first
end
# Load a document from the database by id
def get(id)
doc = database.get id
new(doc)
end
end
end

View file

@ -64,7 +64,7 @@ module CouchRest
# Takes a hash as argument, and applies the values by using writer methods
# for each key. It doesn't save the document at the end. Raises a NoMethodError if the corresponding methods are
# missing. In case of error, no attributes are changed.
def update_attributes_without_saving hash
def update_attributes_without_saving(hash)
hash.each do |k, v|
raise NoMethodError, "#{k}= method not available, use key_accessor or key_writer :#{k}" unless self.respond_to?("#{k}=")
end
@ -76,7 +76,7 @@ module CouchRest
# Takes a hash as argument, and applies the values by using writer methods
# for each key. Raises a NoMethodError if the corresponding methods are
# missing. In case of error, no attributes are changed.
def update_attributes hash
def update_attributes(hash)
update_attributes_without_saving hash
save
end
@ -86,7 +86,7 @@ module CouchRest
# Overridden to set the unique ID.
# Returns a boolean value
def save bulk = false
def save(bulk = false)
set_unique_id if new_document? && self.respond_to?(:set_unique_id)
result = database.save_doc(self, bulk)
result["ok"] == true