Class: RubyEventStore::BatchEnumerator
- Inherits:
-
Object
- Object
- RubyEventStore::BatchEnumerator
- Defined in:
- lib/ruby_event_store/batch_enumerator.rb
Instance Method Summary collapse
- #each ⇒ Object
- #first ⇒ Object
-
#initialize(batch_size, total_limit, reader) ⇒ BatchEnumerator
constructor
A new instance of BatchEnumerator.
- #to_a ⇒ Object
Constructor Details
#initialize(batch_size, total_limit, reader) ⇒ BatchEnumerator
Returns a new instance of BatchEnumerator.
5 6 7 8 9 |
# File 'lib/ruby_event_store/batch_enumerator.rb', line 5 def initialize(batch_size, total_limit, reader) @batch_size = batch_size @total_limit = total_limit @reader = reader end |
Instance Method Details
#each ⇒ Object
11 12 13 14 15 16 17 18 19 20 21 |
# File 'lib/ruby_event_store/batch_enumerator.rb', line 11 def each return to_enum unless block_given? 0.step(total_limit - 1, batch_size) do |batch_offset| batch_limit = [batch_size, total_limit - batch_offset].min result = reader.call(batch_offset, batch_limit) yield result if result.any? break if result.size < batch_size end end |
#first ⇒ Object
23 24 25 |
# File 'lib/ruby_event_store/batch_enumerator.rb', line 23 def first each.first end |
#to_a ⇒ Object
27 28 29 |
# File 'lib/ruby_event_store/batch_enumerator.rb', line 27 def to_a each.to_a end |