Module: MongoEachBy::Criteria

Defined in:
lib/mongo_each_by/criteria.rb

Instance Method Summary collapse

Instance Method Details

#each_by(by, &block) ⇒ Object



3
4
5
6
7
8
9
10
11
12
13
14
15
16
# File 'lib/mongo_each_by/criteria.rb', line 3

def each_by(by, &block)
  idx = 0
  total = 0
  set_limit = options[:limit]
  while ((results = ordered_clone.limit(by).skip(idx)) && results.any?)
    results.each do |result|
      return self if set_limit and set_limit >= total
      total += 1
      yield result
    end
    idx += by
  end
  self
end