Class: Kettle::Ndjson::EventStream
- Inherits:
-
Object
- Object
- Kettle::Ndjson::EventStream
- Defined in:
- lib/kettle/ndjson.rb,
sig/kettle/ndjson.rbs
Instance Attribute Summary collapse
-
#types ⇒ Array[String]
readonly
Returns the value of attribute types.
Instance Method Summary collapse
- #emit(payload) ⇒ void
-
#initialize(io, types:) ⇒ EventStream
constructor
A new instance of EventStream.
Constructor Details
#initialize(io, types:) ⇒ EventStream
Returns a new instance of EventStream.
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
#types ⇒ Array[String] (readonly)
Returns the value of attribute types.
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.
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 |