Class: Roda::RodaPlugins::SSE::Output

Inherits:
Object
  • Object
show all
Defined in:
lib/roda/plugins/sse.rb

Instance Method Summary collapse

Constructor Details

#initialize(stream) ⇒ Output

Returns a new instance of Output.



21
22
23
# File 'lib/roda/plugins/sse.rb', line 21

def initialize(stream)
  @stream = stream
end

Instance Method Details

#<<(message) ⇒ Object



31
32
33
34
# File 'lib/roda/plugins/sse.rb', line 31

def <<(message)
  write(message)
  self
end

#close(error = nil) ⇒ Object



36
37
38
39
40
41
# File 'lib/roda/plugins/sse.rb', line 36

def close(error = nil)
  if stream = @stream
    @stream = nil
    stream.close_write(error)
  end
end

#write(message) ⇒ Object



25
26
27
28
29
# File 'lib/roda/plugins/sse.rb', line 25

def write(message)
  data = message.to_s
  @stream.write(data)
  return data.bytesize
end