made get not raise an exception anymore, use get! instead if you need to raise exceptions.

* ExtendedDocument.get doesn't raise an exception anymore. If no documents are found nil is returned.
* ExtendedDocument.get! works the say #get used to work and will raise an exception if a document isn't found.
This commit is contained in:
Matt Aimonetti 2009-07-22 16:05:55 -07:00
parent 87d246d30e
commit 5cd2eaf18a
3 changed files with 46 additions and 3 deletions

View file

@ -39,7 +39,38 @@ module CouchRest
end
# Load a document from the database by id
# No exceptions will be raised if the document isn't found
#
# ==== Returns
# Object:: if the document was found
# or
# Nil::
#
# === Parameters
# id<String, Integer>:: Document ID
# db<Database>:: optional option to pass a custom database to use
def get(id, db = database)
begin
doc = db.get id
rescue
nil
else
new(doc)
end
end
# Load a document from the database by id
# An exception will be raised if the document isn't found
#
# ==== Returns
# Object:: if the document was found
# or
# Exception
#
# === Parameters
# id<String, Integer>:: Document ID
# db<Database>:: optional option to pass a custom database to use
def get!(id, db = database)
doc = db.get id
new(doc)
end