Class: Rage::SSE::ConnectionProxy

Inherits:
Object
  • Object
show all
Defined in:
lib/rage/sse/connection_proxy.rb

Overview

This class acts as a proxy for the underlying SSE connection, providing a simplified and safe interface for interacting with the stream. It ensures that operations are only performed on an open connection and abstracts away the direct connection handling.

Example:

render sse: ->(connection) do
  # `connection` is an instance of Rage::SSE::ConnectionProxy
end

Instance Method Summary collapse

Instance Method Details

#closeObject Also known as: close_write

Closes the SSE stream.



32
33
34
# File 'lib/rage/sse/connection_proxy.rb', line 32

def close
  @connection.close
end

#close_readObject

A no-op method to maintain interface compatibility. Reading from an SSE stream is not supported on the server side.



58
59
# File 'lib/rage/sse/connection_proxy.rb', line 58

def close_read
end

#closed?Boolean

Checks if the SSE stream is closed.

Returns:

  • (Boolean)


40
41
42
# File 'lib/rage/sse/connection_proxy.rb', line 40

def closed?
  !@connection.open?
end

#flushObject

A no-op method to maintain interface compatibility. Flushing is handled by the underlying connection.

Raises:

  • (IOError)

    if the stream is already closed.



47
48
49
# File 'lib/rage/sse/connection_proxy.rb', line 47

def flush
  raise IOError, "closed stream" unless @connection.open?
end

#readObject

A no-op method to maintain interface compatibility. Reading from an SSE stream is not supported on the server side.



53
54
# File 'lib/rage/sse/connection_proxy.rb', line 53

def read(...)
end

#write(data) ⇒ Object Also known as: <<

Writes data to the SSE stream.

Parameters:

  • data (#to_s)

Raises:

  • (IOError)

    if the stream is already closed.



24
25
26
27
# File 'lib/rage/sse/connection_proxy.rb', line 24

def write(data)
  raise IOError, "closed stream" unless @connection.open?
  @connection.write(data.to_s)
end