Class: Humanoid::Cursor
- Includes:
- Enumerable
- Defined in:
- lib/humanoid/cursor.rb
Constant Summary collapse
- OPERATIONS =
Operations on the Mongo::Cursor object that will not get overriden by the Humanoid::Cursor are defined here.
[ :admin, :close, :closed?, :count, :explain, :fields, :full_collection_name, :hint, :limit, :order, :query_options_hash, :query_opts, :selector, :skip, :snapshot, :sort, :timeout ]
Instance Attribute Summary collapse
-
#collection ⇒ Object
readonly
Returns the value of attribute collection.
Instance Method Summary collapse
-
#each ⇒ Object
Iterate over each document in the cursor and yield to it.
-
#initialize(klass, collection, cursor) ⇒ Cursor
constructor
Create the new
Humanoid::Cursor
. -
#next_document ⇒ Object
Return the next document in the cursor.
-
#to_a ⇒ Object
Returns an array of all the documents in the cursor.
Constructor Details
#initialize(klass, collection, cursor) ⇒ Cursor
Create the new Humanoid::Cursor
.
Options:
collection: The Humanoid::Collection instance. cursor: The Mongo::Cursor to be proxied.
Example:
Humanoid::Cursor.new(Person, cursor)
59 60 61 |
# File 'lib/humanoid/cursor.rb', line 59 def initialize(klass, collection, cursor) @klass, @collection, @cursor = klass, collection, cursor end |
Instance Attribute Details
#collection ⇒ Object (readonly)
Returns the value of attribute collection.
27 28 29 |
# File 'lib/humanoid/cursor.rb', line 27 def collection @collection end |
Instance Method Details
#each ⇒ Object
Iterate over each document in the cursor and yield to it.
Example:
cursor.each { |doc| p doc.title }
43 44 45 46 47 |
# File 'lib/humanoid/cursor.rb', line 43 def each @cursor.each do |document| yield Humanoid::Factory.build(@klass, document) end end |