Added helper for accessing the top level document. And more rails compatibility.

This commit is contained in:
Peter Gumeson 2009-05-28 22:42:30 -07:00
parent 936ce54449
commit d012380b67
5 changed files with 80 additions and 0 deletions

View file

@ -110,6 +110,19 @@ module CouchRest
self.class.properties
end
# Gets a reference to the actual document in the DB
# Calls up to the next document if there is one,
# Otherwise we're at the top and we return self
def base_doc
return self if base_doc?
@casted_by.base_doc
end
# Checks if we're the top document
def base_doc?
!@casted_by
end
# 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.