Class: Anycable::Socket

Inherits:
Object
  • Object
show all
Defined in:
lib/anycable/socket.rb

Overview

Socket mock to be used with application connection

Instance Attribute Summary collapse

Instance Method Summary collapse

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

#envObject (readonly)

Returns the value of attribute env.



6
7
8
# File 'lib/anycable/socket.rb', line 6

def env
  @env
end

#transmissionsObject (readonly)

Returns the value of attribute transmissions.



6
7
8
# File 'lib/anycable/socket.rb', line 6

def transmissions
  @transmissions
end

Instance Method Details

#closeObject



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

Returns:

  • (Boolean)


40
41
42
# File 'lib/anycable/socket.rb', line 40

def closed?
  @closed == true
end

#stop_streams?Boolean

Returns:

  • (Boolean)


44
45
46
# File 'lib/anycable/socket.rb', line 44

def stop_streams?
  @stop_all_streams == true
end

#streamsObject



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(websocket_message)
  transmissions << websocket_message
end

#unsubscribe(_channel, _broadcasting) ⇒ Object

Raises:

  • (NotImplementedError)


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