Class: Segment::Analytics::MessageBatch
- Inherits:
-
Object
- Object
- Segment::Analytics::MessageBatch
- Extended by:
- Forwardable
- Includes:
- Defaults::MessageBatch, Logging
- Defined in:
- lib/segment/analytics/message_batch.rb
Overview
A batch of ‘Message`s to be sent to the API
Constant Summary
Constants included from Defaults::MessageBatch
Defaults::MessageBatch::MAX_BYTES, Defaults::MessageBatch::MAX_SIZE
Instance Method Summary collapse
- #<<(message) ⇒ Object
- #clear ⇒ Object
- #full? ⇒ Boolean
-
#initialize(max_message_count) ⇒ MessageBatch
constructor
A new instance of MessageBatch.
Methods included from Logging
Constructor Details
#initialize(max_message_count) ⇒ MessageBatch
Returns a new instance of MessageBatch.
11 12 13 14 15 |
# File 'lib/segment/analytics/message_batch.rb', line 11 def initialize() @messages = [] @max_message_count = @json_size = 0 end |
Instance Method Details
#<<(message) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/segment/analytics/message_batch.rb', line 17 def <<() if .too_big? logger.error('a message exceeded the maximum allowed size') else @messages << @json_size += .json_size + 1 # One byte for the comma end end |
#clear ⇒ Object
30 31 32 33 |
# File 'lib/segment/analytics/message_batch.rb', line 30 def clear @messages.clear @json_size = 0 end |
#full? ⇒ Boolean
26 27 28 |
# File 'lib/segment/analytics/message_batch.rb', line 26 def full? item_count_exhausted? || size_exhausted? end |