Class: ActionCable::Connection::MessageBuffer
Do not use. This class is for internal use only.
Relationships & Source Files | |
Inherits: | Object |
Defined in: | actioncable/lib/action_cable/connection/message_buffer.rb |
Overview
Allows us to buffer messages received from the WebSocket
before the ::ActionCable::Connection
has been fully initialized, and is ready to receive them.
Class Method Summary
- .new(connection) ⇒ MessageBuffer constructor
Instance Attribute Summary
- #processing? ⇒ Boolean readonly
- #buffered_messages readonly private
- #connection readonly private
Instance Method Summary
- #append(message)
- #process!
- #buffer(message) private
- #receive(message) private
- #receive_buffered_messages private
- #valid?(message) ⇒ Boolean private
Constructor Details
.new(connection) ⇒ MessageBuffer
# File 'actioncable/lib/action_cable/connection/message_buffer.rb', line 10
def initialize(connection) @connection = connection @buffered_messages = [] end
Instance Attribute Details
#buffered_messages (readonly, private)
[ GitHub ]# File 'actioncable/lib/action_cable/connection/message_buffer.rb', line 38
attr_reader :
#connection (readonly, private)
[ GitHub ]# File 'actioncable/lib/action_cable/connection/message_buffer.rb', line 37
attr_reader :connection
#processing? ⇒ Boolean
(readonly)
[ GitHub ]
# File 'actioncable/lib/action_cable/connection/message_buffer.rb', line 27
def processing? @processing end
Instance Method Details
#append(message)
[ GitHub ]# File 'actioncable/lib/action_cable/connection/message_buffer.rb', line 15
def append( ) if valid? if processing? receive else buffer end else connection.logger.error "Couldn't handle non-string message: #{ .class}" end end
#buffer(message) (private)
[ GitHub ]# File 'actioncable/lib/action_cable/connection/message_buffer.rb', line 48
def buffer( ) << end
#process!
[ GitHub ]# File 'actioncable/lib/action_cable/connection/message_buffer.rb', line 31
def process! @processing = true end
#receive(message) (private)
[ GitHub ]# File 'actioncable/lib/action_cable/connection/message_buffer.rb', line 44
def receive( ) connection.receive end
#receive_buffered_messages (private)
[ GitHub ]# File 'actioncable/lib/action_cable/connection/message_buffer.rb', line 52
def receive .shift until .empty? end
#valid?(message) ⇒ Boolean
(private)
# File 'actioncable/lib/action_cable/connection/message_buffer.rb', line 40
def valid?( ) .is_a?(String) end