Module: Superstore::Relation::Scrolling

Defined in:
lib/superstore/relation/scrolling.rb

Instance Method Summary collapse

Instance Method Details

#scroll_each(options = {}) ⇒ Object



4
5
6
7
8
9
10
# File 'lib/superstore/relation/scrolling.rb', line 4

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

  scroll_results(batch_size) do |attributes|
    yield klass.instantiate(attributes)
  end
end

#scroll_in_batches(options = {}) {|batch| ... } ⇒ Object

Yields:

  • (batch)


12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
# File 'lib/superstore/relation/scrolling.rb', line 12

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

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

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

  yield(batch) if batch.any?
end