Sha256: 1a44a3e95a30c6a959fd9a089db8bfdb81797f2647085264abe4dea0e7d8c619
Contents?: true
Size: 890 Bytes
Versions: 62
Compression:
Stored size: 890 Bytes
Contents
module Mongoid class Criteria def each_by(by, &block) i = 0 total = 0 set_limit = options[:limit] while (results = ordered_clone.skip(i).limit(by)) && results.exists? results.each do |result| return self if set_limit && set_limit >= total && total > 0 total += 1 yield result end i += by end self end def each_slice_of(size, &block) total = 0 set_limit = options[:limit] while (results = ordered_clone.skip(total).limit(size)) && results.exists? total += size if set_limit && total > set_limit yield results.first(total - set_limit) return self else yield results end end self end private def ordered_clone options[:sort] ? clone : clone.asc(:_id) end end end
Version data entries
62 entries across 62 versions & 1 rubygems