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:
parent
87d246d30e
commit
5cd2eaf18a
3 changed files with 46 additions and 3 deletions
|
@ -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
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue