Class: Logux::Process::Batch
- Inherits:
-
Object
- Object
- Logux::Process::Batch
- Defined in:
- lib/logux/process/batch.rb
Instance Attribute Summary collapse
-
#batch ⇒ Object
readonly
Returns the value of attribute batch.
-
#stream ⇒ Object
readonly
Returns the value of attribute stream.
Instance Method Summary collapse
- #call ⇒ Object
-
#initialize(stream:, batch:) ⇒ Batch
constructor
A new instance of Batch.
- #preprocess_action(chunk) ⇒ Object
- #preprocess_auth(chunk) ⇒ Object
- #preprocessed_batch ⇒ Object
- #process_action(chunk:) ⇒ Object
- #process_auth(chunk:) ⇒ Object
Constructor Details
#initialize(stream:, batch:) ⇒ Batch
Returns a new instance of Batch.
8 9 10 11 |
# File 'lib/logux/process/batch.rb', line 8 def initialize(stream:, batch:) @stream = stream @batch = batch end |
Instance Attribute Details
#batch ⇒ Object (readonly)
Returns the value of attribute batch.
6 7 8 |
# File 'lib/logux/process/batch.rb', line 6 def batch @batch end |
#stream ⇒ Object (readonly)
Returns the value of attribute stream.
6 7 8 |
# File 'lib/logux/process/batch.rb', line 6 def stream @stream end |
Instance Method Details
#call ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/logux/process/batch.rb', line 13 def call last_chunk = batch.size - 1 preprocessed_batch.map.with_index do |chunk, index| case chunk[:type] when :action process_action(chunk: chunk.slice(:action, :meta)) when :auth process_auth(chunk: chunk[:auth]) end stream.write(',') if index != last_chunk end end |
#preprocess_action(chunk) ⇒ Object
45 46 47 48 49 |
# File 'lib/logux/process/batch.rb', line 45 def preprocess_action(chunk) { type: :action, action: Logux::Action.new(chunk[1]), meta: Logux::Meta.new(chunk[2]) } end |
#preprocess_auth(chunk) ⇒ Object
51 52 53 54 55 56 |
# File 'lib/logux/process/batch.rb', line 51 def preprocess_auth(chunk) { type: :auth, auth: Logux::Auth.new(user_id: chunk[1], credentials: chunk[2], auth_id: chunk[3]) } end |
#preprocessed_batch ⇒ Object
34 35 36 37 38 39 40 41 42 43 |
# File 'lib/logux/process/batch.rb', line 34 def preprocessed_batch @preprocessed_batch ||= batch.map do |chunk| case chunk[0] when 'action' preprocess_action(chunk) when 'auth' preprocess_auth(chunk) end end end |