Class: CouchDB::Collection
- Inherits:
-
Object
- Object
- CouchDB::Collection
- Defined in:
- lib/couchdb/collection.rb
Overview
Collection is a proxy class for the result-set of a CouchDB view. It provides all read-only methods of an array. The loading of content is lazy and will be triggered on the first request.
Defined Under Namespace
Classes: DocumentsProxy
Constant Summary collapse
- REQUEST_PARAMETER_KEYS =
[ :key, :startkey, :startkey_docid, :endkey, :endkey_docid, :limit, :stale, :descending, :skip, :group, :group_level, :reduce, :inclusive_end, :include_docs ].freeze
- ARRAY_METHOD_NAMES =
[ :[], :at, :collect, :compact, :count, :cycle, :each, :each_index, :empty?, :fetch, :index, :first, :flatten, :include?, :join, :last, :length, :map, :pack, :reject, :reverse, :reverse_each, :rindex, :sample, :shuffle, :size, :slice, :sort, :take, :to_a, :to_ary, :values_at, :zip ].freeze
Instance Attribute Summary collapse
-
#database ⇒ Object
readonly
Returns the value of attribute database.
-
#documents ⇒ Object
readonly
Returns the value of attribute documents.
-
#options ⇒ Object
readonly
Returns the value of attribute options.
-
#url ⇒ Object
readonly
Returns the value of attribute url.
Instance Method Summary collapse
-
#initialize(database, url, options = { }) ⇒ Collection
constructor
A new instance of Collection.
- #method_missing(method_name, *arguments, &block) ⇒ Object
- #respond_to?(method_name) ⇒ Boolean
- #total_count ⇒ Object
Constructor Details
#initialize(database, url, options = { }) ⇒ Collection
Returns a new instance of Collection.
28 29 30 31 |
# File 'lib/couchdb/collection.rb', line 28 def initialize(database, url, = { }) @database, @url, @options = database, url, @documents = DocumentsProxy.new self end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *arguments, &block) ⇒ Object
42 43 44 45 46 47 48 49 |
# File 'lib/couchdb/collection.rb', line 42 def method_missing(method_name, *arguments, &block) if ARRAY_METHOD_NAMES.include?(method_name) fetch @entries.send method_name, *arguments, &block else super end end |
Instance Attribute Details
#database ⇒ Object (readonly)
Returns the value of attribute database.
23 24 25 |
# File 'lib/couchdb/collection.rb', line 23 def database @database end |
#documents ⇒ Object (readonly)
Returns the value of attribute documents.
26 27 28 |
# File 'lib/couchdb/collection.rb', line 26 def documents @documents end |
#options ⇒ Object (readonly)
Returns the value of attribute options.
25 26 27 |
# File 'lib/couchdb/collection.rb', line 25 def @options end |
#url ⇒ Object (readonly)
Returns the value of attribute url.
24 25 26 |
# File 'lib/couchdb/collection.rb', line 24 def url @url end |
Instance Method Details
#respond_to?(method_name) ⇒ Boolean
38 39 40 |
# File 'lib/couchdb/collection.rb', line 38 def respond_to?(method_name) ARRAY_METHOD_NAMES.include?(method_name) || super end |
#total_count ⇒ Object
33 34 35 36 |
# File 'lib/couchdb/collection.rb', line 33 def total_count unless @total_count @total_count end |