Module: CouchRest::Mixins::DocumentQueries::ClassMethods
- Defined in:
- lib/couchrest/mixins/document_queries.rb
Instance Method Summary collapse
-
#all(opts = {}, &block) ⇒ Object
Load all documents that have the “couchrest-type” field equal to the name of the current class.
-
#first(opts = {}) ⇒ Object
Load the first document that have the “couchrest-type” field equal to the name of the current class.
-
#get(id) ⇒ Object
Load a document from the database by id.
Instance Method Details
#all(opts = {}, &block) ⇒ Object
Load all documents that have the “couchrest-type” field equal to the name of the current class. Take the standard set of CouchRest::Database#view options.
14 15 16 17 18 19 20 |
# File 'lib/couchrest/mixins/document_queries.rb', line 14 def all(opts = {}, &block) self.design_doc ||= Design.new(default_design_doc) unless design_doc_fresh refresh_design_doc end view(:all, opts, &block) end |
#first(opts = {}) ⇒ Object
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
CouchRest::Database#view
options for more info.
33 34 35 36 |
# File 'lib/couchrest/mixins/document_queries.rb', line 33 def first(opts = {}) first_instance = self.all(opts.merge!(:limit => 1)) first_instance.empty? ? nil : first_instance.first end |
#get(id) ⇒ Object
Load a document from the database by id
39 40 41 42 |
# File 'lib/couchrest/mixins/document_queries.rb', line 39 def get(id) doc = database.get id new(doc) end |