Module: CouchRest::Model::DocumentQueries::ClassMethods
- Defined in:
- lib/couchrest/model/document_queries.rb
Instance Method Summary collapse
-
#count ⇒ Object
Wrapper for the master design documents all method to provide a total count of entries.
-
#first ⇒ Object
Wrapper for the master design document’s first method on all view.
-
#get(id, db = database) ⇒ Object
(also: #find)
Load a document from the database by id No exceptions will be raised if the document isn’t found.
-
#get!(id, db = database) ⇒ Object
(also: #find!)
Load a document from the database by id An exception will be raised if the document isn’t found.
-
#last ⇒ Object
Wrapper for the master design document’s last method on all view.
Instance Method Details
#count ⇒ Object
Wrapper for the master design documents all method to provide a total count of entries.
10 11 12 |
# File 'lib/couchrest/model/document_queries.rb', line 10 def count all.count end |
#first ⇒ Object
Wrapper for the master design document’s first method on all view.
15 16 17 |
# File 'lib/couchrest/model/document_queries.rb', line 15 def first all.first end |
#get(id, db = database) ⇒ Object Also known as: find
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
35 36 37 38 39 40 41 |
# File 'lib/couchrest/model/document_queries.rb', line 35 def get(id, db = database) begin get!(id, db) rescue nil end end |
#get!(id, db = database) ⇒ Object Also known as: find!
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
55 56 57 58 59 60 61 62 |
# File 'lib/couchrest/model/document_queries.rb', line 55 def get!(id, db = database) raise CouchRest::Model::DocumentNotFound if id.blank? doc = db.get id build_from_database(doc) rescue RestClient::ResourceNotFound raise CouchRest::Model::DocumentNotFound end |
#last ⇒ Object
Wrapper for the master design document’s last method on all view.
20 21 22 |
# File 'lib/couchrest/model/document_queries.rb', line 20 def last all.last end |