Implement #get! and #find! class methods
Signed-off-by: Marcos Tapajós <tapajos@gmail.com>
This commit is contained in:
parent
fcd9e2ba8e
commit
9b8564d9a8
4 changed files with 43 additions and 2 deletions
|
@ -87,7 +87,14 @@ module CouchRest
|
|||
doc
|
||||
end
|
||||
alias :find :get
|
||||
|
||||
|
||||
def get!(id)
|
||||
doc = @klass.get!(id, @database)
|
||||
doc.database = @database if doc && doc.respond_to?(:database)
|
||||
doc
|
||||
end
|
||||
alias :find! :get!
|
||||
|
||||
# Views
|
||||
|
||||
def has_view?(view)
|
||||
|
|
|
@ -86,9 +86,12 @@ module CouchRest
|
|||
# id<String, Integer>:: Document ID
|
||||
# db<Database>:: optional option to pass a custom database to use
|
||||
def get!(id, db = database)
|
||||
raise "Missing or empty document ID" if id.to_s.empty?
|
||||
raise CouchRest::Model::DocumentNotFound if id.blank?
|
||||
|
||||
doc = db.get id
|
||||
build_from_database(doc)
|
||||
rescue RestClient::ResourceNotFound
|
||||
raise CouchRest::Model::DocumentNotFound
|
||||
end
|
||||
alias :find! :get!
|
||||
|
||||
|
|
|
@ -19,5 +19,7 @@ module CouchRest
|
|||
end
|
||||
end
|
||||
end
|
||||
|
||||
class DocumentNotFound < Errors::CouchRestModelError; end
|
||||
end
|
||||
end
|
||||
|
|
Loading…
Add table
Add a link
Reference in a new issue