Class: Xeno::StreamsController::NdjsonWriter

Inherits:
Object
  • Object
show all
Defined in:
app/controllers/xeno/streams_controller.rb

Overview

NDJSON framing: one envelope per line (type/index live inside the envelope); a bare newline as keepalive — line parsers skip empties.

Instance Method Summary collapse

Constructor Details

#initialize(stream) ⇒ NdjsonWriter

Returns a new instance of NdjsonWriter.



32
33
34
# File 'app/controllers/xeno/streams_controller.rb', line 32

def initialize(stream)
  @stream = stream
end

Instance Method Details

#closeObject



39
# File 'app/controllers/xeno/streams_controller.rb', line 39

def close = @stream.close

#content_typeObject



36
# File 'app/controllers/xeno/streams_controller.rb', line 36

def content_type = "application/x-ndjson"

#event(record) ⇒ Object



37
# File 'app/controllers/xeno/streams_controller.rb', line 37

def event(record) = @stream.write("#{JSON.generate(record.envelope)}\n")

#keepaliveObject



38
# File 'app/controllers/xeno/streams_controller.rb', line 38

def keepalive = @stream.write("\n")