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.
132 133 134 135 |
# File 'lib/kettle/ndjson.rb', line 132 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.
137 138 139 |
# File 'lib/kettle/ndjson.rb', line 137 def types @types end |
Instance Method Details
#emit(payload) ⇒ void
This method returns an undefined value.
139 140 141 142 143 144 |
# File 'lib/kettle/ndjson.rb', line 139 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 |