Started on the ExtendedDocument class with features moved to mixins.
Properties got added, they define getters, setters and aliases. They will also be the base of the new validation system.
This commit is contained in:
parent
0c27fa6498
commit
83d7341553
12 changed files with 533 additions and 8 deletions
42
lib/couchrest/mixins/document_queries.rb
Normal file
42
lib/couchrest/mixins/document_queries.rb
Normal file
|
@ -0,0 +1,42 @@
|
|||
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
|
||||
|
||||
end
|
||||
|
||||
end
|
||||
end
|
||||
end
|
Loading…
Add table
Add a link
Reference in a new issue