Class: Karafka::Params::ParamsBatch
- Inherits:
-
Object
- Object
- Karafka::Params::ParamsBatch
- Includes:
- Enumerable
- Defined in:
- lib/karafka/params/params_batch.rb
Overview
Params internally are lazy loaded before first use. That way we can skip parsing process if we have after_fetch that rejects some incoming messages without using params It can be also used when handling really heavy data (in terms of parsing).
Params batch represents a set of messages received from Kafka.
Instance Method Summary collapse
- #each {|each| ... } ⇒ Object
-
#initialize(messages_batch, topic_parser) ⇒ ParamsBatch
constructor
Builds up a params batch based on raw kafka messages.
-
#last ⇒ Karafka::Params::Params
Last element after the unparsing process.
-
#parsed ⇒ Array<Karafka::Params::Params>
Returns all the params in a loaded state, so they can be used for batch insert, etc.
-
#to_a ⇒ Array<Karafka::Params::Params>
Pure array with params (not parsed).
Constructor Details
#initialize(messages_batch, topic_parser) ⇒ ParamsBatch
Builds up a params batch based on raw kafka messages
15 16 17 18 19 |
# File 'lib/karafka/params/params_batch.rb', line 15 def initialize(, topic_parser) @params_batch = .map! do || Karafka::Params::Params.build(, topic_parser) end end |
Instance Method Details
#each {|each| ... } ⇒ Object
Invocation of this method will cause loading and parsing each param after another. If you want to get access without parsing, please access params_batch directly
24 25 26 |
# File 'lib/karafka/params/params_batch.rb', line 24 def each @params_batch.each { |param| yield(param.retrieve!) } end |
#last ⇒ Karafka::Params::Params
Returns last element after the unparsing process.
36 37 38 |
# File 'lib/karafka/params/params_batch.rb', line 36 def last @params_batch.last.retrieve! end |
#parsed ⇒ Array<Karafka::Params::Params>
Returns all the params in a loaded state, so they can be used for batch insert, etc. Without invoking all, up until first use, they won’t be parsed
31 32 33 |
# File 'lib/karafka/params/params_batch.rb', line 31 def parsed each(&:itself) end |
#to_a ⇒ Array<Karafka::Params::Params>
Returns pure array with params (not parsed).
41 42 43 |
# File 'lib/karafka/params/params_batch.rb', line 41 def to_a @params_batch end |