Class: Rage::SSE::ConnectionProxy
- Inherits:
-
Object
- Object
- Rage::SSE::ConnectionProxy
- 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
-
#close ⇒ Object
(also: #close_write)
Closes the SSE stream.
-
#close_read ⇒ Object
A no-op method to maintain interface compatibility.
-
#closed? ⇒ Boolean
Checks if the SSE stream is closed.
-
#flush ⇒ Object
A no-op method to maintain interface compatibility.
-
#read ⇒ Object
A no-op method to maintain interface compatibility.
-
#write(data) ⇒ Object
(also: #<<)
Writes data to the SSE stream.
Instance Method Details
#close ⇒ Object 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_read ⇒ Object
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.
40 41 42 |
# File 'lib/rage/sse/connection_proxy.rb', line 40 def closed? !@connection.open? end |
#flush ⇒ Object
A no-op method to maintain interface compatibility. Flushing is handled by the underlying connection.
47 48 49 |
# File 'lib/rage/sse/connection_proxy.rb', line 47 def flush raise IOError, "closed stream" unless @connection.open? end |
#read ⇒ Object
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.
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 |