Class: Lookbook::Websocket

Inherits:
Object
  • Object
show all
Defined in:
lib/lookbook/websocket.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(engine_mount_path, logger: Lookbook.logger) ⇒ Websocket

Returns a new instance of Websocket.



5
6
7
8
9
10
11
12
13
14
15
16
17
# File 'lib/lookbook/websocket.rb', line 5

def initialize(engine_mount_path, logger: Lookbook.logger)
  @engine_mount_path = engine_mount_path
  @logger = logger

  logger.info "Initializing websocket"

  if Gem::Version.new(Rails.version) >= Gem::Version.new(6.0)
    @server = ActionCable::Server::Base.new config: cable_config
  else
    @server = ActionCable::Server::Base.new
    @server.config = cable_config
  end
end

Instance Attribute Details

#engine_mount_pathObject (readonly)

Returns the value of attribute engine_mount_path.



3
4
5
# File 'lib/lookbook/websocket.rb', line 3

def engine_mount_path
  @engine_mount_path
end

#loggerObject (readonly)

Returns the value of attribute logger.



3
4
5
# File 'lib/lookbook/websocket.rb', line 3

def logger
  @logger
end

#serverObject (readonly)

Returns the value of attribute server.



3
4
5
# File 'lib/lookbook/websocket.rb', line 3

def server
  @server
end

Class Method Details

.noopObject



38
39
40
# File 'lib/lookbook/websocket.rb', line 38

def self.noop
  NullWebsocket.new
end

Instance Method Details

#broadcast(message, payload = nil) ⇒ Object



19
20
21
22
# File 'lib/lookbook/websocket.rb', line 19

def broadcast(message, payload = nil)
  logger.debug message.to_s
  server.broadcast(message.to_s, payload.to_h)
end

#full_mount_pathObject



28
29
30
# File 'lib/lookbook/websocket.rb', line 28

def full_mount_path
  "#{engine_mount_path}/#{mount_path}".gsub("//", "/")
end

#mount_pathObject



24
25
26
# File 'lib/lookbook/websocket.rb', line 24

def mount_path
  "/cable"
end

#mountable?Boolean Also known as: mounted?

Returns:

  • (Boolean)


32
33
34
# File 'lib/lookbook/websocket.rb', line 32

def mountable?
  true
end