Module: Superstore::Batches
- Included in:
- Scope
- Defined in:
- lib/superstore/scope/batches.rb
Instance Method Summary collapse
Instance Method Details
#find_each(options = {}) ⇒ Object
3 4 5 6 7 8 9 |
# File 'lib/superstore/scope/batches.rb', line 3 def find_each( = {}) batch_size = [:batch_size] || 1000 klass.adapter.scroll(self, batch_size) do |key, attributes| yield klass.instantiate(key, attributes) end end |
#find_in_batches(options = {}) {|batch| ... } ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/superstore/scope/batches.rb', line 11 def find_in_batches( = {}) batch_size = [:batch_size] || 1000 batch = [] find_each() do |record| batch << record if batch.size == batch_size yield batch batch = [] end end yield(batch) if batch.any? end |