Class: Anycable::Socket
- Inherits:
-
Object
- Object
- Anycable::Socket
- Defined in:
- lib/anycable/socket.rb
Overview
Socket mock to be used with application connection
Instance Attribute Summary collapse
-
#env ⇒ Object
readonly
Returns the value of attribute env.
-
#transmissions ⇒ Object
readonly
Returns the value of attribute transmissions.
Instance Method Summary collapse
- #close ⇒ Object
- #closed? ⇒ Boolean
-
#initialize(env: nil) ⇒ Socket
constructor
A new instance of Socket.
- #stop_streams? ⇒ Boolean
- #streams ⇒ Object
- #subscribe(_channel, broadcasting) ⇒ Object
- #transmit(websocket_message) ⇒ Object
- #unsubscribe(_channel, _broadcasting) ⇒ Object
- #unsubscribe_from_all(_channel) ⇒ Object
Constructor Details
#initialize(env: nil) ⇒ Socket
Returns a new instance of Socket.
8 9 10 11 |
# File 'lib/anycable/socket.rb', line 8 def initialize(env: nil) @transmissions = [] @env = env end |
Instance Attribute Details
#env ⇒ Object (readonly)
Returns the value of attribute env.
6 7 8 |
# File 'lib/anycable/socket.rb', line 6 def env @env end |
#transmissions ⇒ Object (readonly)
Returns the value of attribute transmissions.
6 7 8 |
# File 'lib/anycable/socket.rb', line 6 def transmissions @transmissions end |
Instance Method Details
#close ⇒ Object
33 34 35 36 37 38 |
# File 'lib/anycable/socket.rb', line 33 def close @closed = true @transmissions.clear @streams&.clear @stop_all_streams = true end |
#closed? ⇒ Boolean
40 41 42 |
# File 'lib/anycable/socket.rb', line 40 def closed? @closed == true end |
#stop_streams? ⇒ Boolean
44 45 46 |
# File 'lib/anycable/socket.rb', line 44 def stop_streams? @stop_all_streams == true end |
#streams ⇒ Object
29 30 31 |
# File 'lib/anycable/socket.rb', line 29 def streams @streams ||= [] end |
#subscribe(_channel, broadcasting) ⇒ Object
17 18 19 |
# File 'lib/anycable/socket.rb', line 17 def subscribe(_channel, broadcasting) streams << broadcasting end |
#transmit(websocket_message) ⇒ Object
13 14 15 |
# File 'lib/anycable/socket.rb', line 13 def transmit() transmissions << end |
#unsubscribe(_channel, _broadcasting) ⇒ Object
21 22 23 |
# File 'lib/anycable/socket.rb', line 21 def unsubscribe(_channel, _broadcasting) raise NotImplementedError end |
#unsubscribe_from_all(_channel) ⇒ Object
25 26 27 |
# File 'lib/anycable/socket.rb', line 25 def unsubscribe_from_all(_channel) @stop_all_streams = true end |