lib/plucky/query.rb in plucky-0.6.3 vs lib/plucky/query.rb in plucky-0.6.4
- old
+ new
@@ -59,25 +59,27 @@
docs = query.amend({
:limit => paginator.limit,
:skip => paginator.skip,
}).all
- docs.extend(Pagination::Decorator)
- docs.paginator(paginator)
- docs
+ Pagination::Collection.new(docs, paginator)
end
def find_each(opts={})
query = clone.amend(opts)
- cursor = query.cursor
if block_given?
- cursor.each { |doc| yield doc }
- cursor.rewind!
+ result = nil
+ query.cursor do |cursor|
+ result = cursor
+ cursor.each { |doc| yield doc }
+ cursor.rewind!
+ end
+ result
+ else
+ query.cursor
end
-
- cursor
end
def find_one(opts={})
query = clone.amend(opts)
query.collection.find_one(query.criteria_hash, query.options_hash)
@@ -228,11 +230,11 @@
def options_hash
@options.to_hash
end
- def cursor
- @collection.find(criteria_hash, options_hash)
+ def cursor(&block)
+ @collection.find(criteria_hash, options_hash, &block)
end
private
# Private