added documentation to model#first

This commit is contained in:
Matt Aimonetti 2008-11-03 18:08:14 -08:00
parent 19f587c0d6
commit 1c5feaa845

View file

@ -112,7 +112,7 @@ module CouchRest
end end
# Load all documents that have the "couchrest-type" field equal to the # Load all documents that have the "couchrest-type" field equal to the
# name of the current class. Take thes the standard set of # name of the current class. Take the standard set of
# CouchRest::Database#view options. # CouchRest::Database#view options.
def all opts = {} def all opts = {}
self.generated_design_doc ||= default_design_doc self.generated_design_doc ||= default_design_doc
@ -124,6 +124,17 @@ module CouchRest
fetch_view_with_docs(view_name, opts, raw) fetch_view_with_docs(view_name, opts, raw)
end end
# Load the first document that have the "couchrest-type" field equal to
# the name of the current class.
#
# ==== Returns
# Object:: The first object instance available
# or
# Nil:: if no instances available
#
# ==== Parameters
# opts<Hash>::
# View options, see <tt>CouchRest::Database#view</tt> options for more info.
def first opts = {} def first opts = {}
first_instance = self.all(opts.merge!(:count => 1)) first_instance = self.all(opts.merge!(:count => 1))
first_instance.empty? ? nil : first_instance.first first_instance.empty? ? nil : first_instance.first