Sha256: 86ab8bedf975f1a3469bcca2d7eb27854629342e52246cbd5acef81a34652c70

Contents?: true

Size: 1.32 KB

Versions: 26

Compression:

Stored size: 1.32 KB

Contents

module CouchRest
  module Mixins
    module DocumentQueries
      
      def self.included(base)
        base.extend(ClassMethods)
      end
      
      module ClassMethods
        
        # 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.
        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

        # 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 <tt>CouchRest::Database#view</tt> options for more info.
        def first(opts = {})
          first_instance = self.all(opts.merge!(:limit => 1))
          first_instance.empty? ? nil : first_instance.first
        end
        
        # Load a document from the database by id
        def get(id)
          doc = database.get id
          new(doc)
        end
        
      end
      
    end
  end
end

Version data entries

26 entries across 26 versions & 7 rubygems

Version Path
glasner-couchrest-0.2.2 lib/couchrest/mixins/document_queries.rb
jchris-couchrest-0.16 lib/couchrest/mixins/document_queries.rb
jchris-couchrest-0.17.0 lib/couchrest/mixins/document_queries.rb
jchris-couchrest-0.2.1 lib/couchrest/mixins/document_queries.rb
jchris-couchrest-0.2.2 lib/couchrest/mixins/document_queries.rb
jchris-couchrest-0.2 lib/couchrest/mixins/document_queries.rb
jchris-couchrest-0.22 lib/couchrest/mixins/document_queries.rb
jrun-couchrest-0.17.1 lib/couchrest/mixins/document_queries.rb
jrun-couchrest-0.2.1.1 lib/couchrest/mixins/document_queries.rb
jrun-couchrest-0.2.1 lib/couchrest/mixins/document_queries.rb
mattetti-couchrest-0.13.3 lib/couchrest/mixins/document_queries.rb
mattetti-couchrest-0.14.1 lib/couchrest/mixins/document_queries.rb
mattetti-couchrest-0.14.2 lib/couchrest/mixins/document_queries.rb
mattetti-couchrest-0.14 lib/couchrest/mixins/document_queries.rb
mattetti-couchrest-0.15 lib/couchrest/mixins/document_queries.rb
mattetti-couchrest-0.16 lib/couchrest/mixins/document_queries.rb
mattetti-couchrest-0.17 lib/couchrest/mixins/document_queries.rb
mattetti-couchrest-0.2.1.0 lib/couchrest/mixins/document_queries.rb
mattetti-couchrest-0.2.1 lib/couchrest/mixins/document_queries.rb
mattetti-couchrest-0.2 lib/couchrest/mixins/document_queries.rb