Class: TimeBucketStream::Batch
- Inherits:
-
Object
- Object
- TimeBucketStream::Batch
- Includes:
- Enumerable
- Defined in:
- lib/time_bucket_stream/batch.rb
Instance Attribute Summary collapse
-
#entries ⇒ Object
readonly
Returns the value of attribute entries.
Instance Method Summary collapse
- #delete ⇒ Object
- #each ⇒ Object
- #empty? ⇒ Boolean
- #finished? ⇒ Boolean
-
#initialize(entries:, on_delete:, on_release:) ⇒ Batch
constructor
A new instance of Batch.
- #release ⇒ Object
- #size ⇒ Object (also: #length)
Constructor Details
#initialize(entries:, on_delete:, on_release:) ⇒ Batch
Returns a new instance of Batch.
9 10 11 12 13 14 |
# File 'lib/time_bucket_stream/batch.rb', line 9 def initialize(entries:, on_delete:, on_release:) @entries = entries.map { |id, payload| [id, payload].freeze }.freeze @on_delete = on_delete @on_release = on_release @finished = false end |
Instance Attribute Details
#entries ⇒ Object (readonly)
Returns the value of attribute entries.
7 8 9 |
# File 'lib/time_bucket_stream/batch.rb', line 7 def entries @entries end |
Instance Method Details
#delete ⇒ Object
31 32 33 |
# File 'lib/time_bucket_stream/batch.rb', line 31 def delete finish_with(@on_delete) end |
#each ⇒ Object
16 17 18 19 20 |
# File 'lib/time_bucket_stream/batch.rb', line 16 def each return enum_for(:each) unless block_given? entries.each { |_id, payload| yield payload } end |
#empty? ⇒ Boolean
27 28 29 |
# File 'lib/time_bucket_stream/batch.rb', line 27 def empty? entries.empty? end |
#finished? ⇒ Boolean
39 40 41 |
# File 'lib/time_bucket_stream/batch.rb', line 39 def finished? @finished end |
#release ⇒ Object
35 36 37 |
# File 'lib/time_bucket_stream/batch.rb', line 35 def release finish_with(@on_release) end |
#size ⇒ Object Also known as: length
22 23 24 |
# File 'lib/time_bucket_stream/batch.rb', line 22 def size entries.size end |