Sha256: 469c6227e4469f3d2ee8a19073652777ebfc310d3a17d7839b678729ce989ab2

Contents?: true

Size: 569 Bytes

Versions: 13

Compression:

Stored size: 569 Bytes

Contents

module Superstore
  module Batches
    def find_each(options = {})
      batch_size = options[:batch_size] || 1000

      klass.adapter.scroll(self, batch_size) do |key, attributes|
        yield klass.instantiate(key, attributes)
      end
    end

    def find_in_batches(options = {})
      batch_size = options[:batch_size] || 1000
      batch = []

      find_each(options) do |record|
        batch << record

        if batch.size == batch_size
          yield batch
          batch = []
        end
      end

      yield(batch) if batch.any?
    end
  end
end

Version data entries

13 entries across 13 versions & 1 rubygems

Version Path
superstore-2.4.4 lib/superstore/scope/batches.rb
superstore-2.4.3 lib/superstore/scope/batches.rb
superstore-2.4.2 lib/superstore/scope/batches.rb
superstore-2.4.1 lib/superstore/scope/batches.rb
superstore-2.4.0 lib/superstore/scope/batches.rb
superstore-2.3.0 lib/superstore/scope/batches.rb
superstore-2.2.0 lib/superstore/scope/batches.rb
superstore-2.1.3 lib/superstore/scope/batches.rb
superstore-2.1.2 lib/superstore/scope/batches.rb
superstore-2.1.1 lib/superstore/scope/batches.rb
superstore-2.1.0 lib/superstore/scope/batches.rb
superstore-2.0.1 lib/superstore/scope/batches.rb
superstore-2.0.0 lib/superstore/scope/batches.rb