Class: Kettle::Ndjson::EventStream

Inherits:
Object
  • Object
show all
Defined in:
lib/kettle/ndjson.rb,
sig/kettle/ndjson.rbs

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(io, types:) ⇒ EventStream

Returns a new instance of EventStream.

Parameters:

  • io (Object)
  • types: (Array[String] types)


131
132
133
134
# File 'lib/kettle/ndjson.rb', line 131

def initialize(io, types:)
  @io = io
  @types = types.map(&:to_s)
end

Instance Attribute Details

#typesArray[String] (readonly)

Returns the value of attribute types.

Returns:

  • (Array[String])


136
137
138
# File 'lib/kettle/ndjson.rb', line 136

def types
  @types
end

Instance Method Details

#emit(payload) ⇒ void

This method returns an undefined value.

Parameters:

  • payload (Hash[Symbol, untyped])


138
139
140
141
142
143
# File 'lib/kettle/ndjson.rb', line 138

def emit(payload)
  return unless @types.include?(payload.fetch(:type).to_s)

  @io.puts(JSON.generate(Kettle::Ndjson.compact_payload(payload)))
  @io.flush if @io.respond_to?(:flush)
end