Class: TimeBucketStream::Batch

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/time_bucket_stream/batch.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#entriesObject (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

#deleteObject



31
32
33
# File 'lib/time_bucket_stream/batch.rb', line 31

def delete
  finish_with(@on_delete)
end

#eachObject



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

Returns:

  • (Boolean)


27
28
29
# File 'lib/time_bucket_stream/batch.rb', line 27

def empty?
  entries.empty?
end

#finished?Boolean

Returns:

  • (Boolean)


39
40
41
# File 'lib/time_bucket_stream/batch.rb', line 39

def finished?
  @finished
end

#releaseObject



35
36
37
# File 'lib/time_bucket_stream/batch.rb', line 35

def release
  finish_with(@on_release)
end

#sizeObject Also known as: length



22
23
24
# File 'lib/time_bucket_stream/batch.rb', line 22

def size
  entries.size
end