Class: Lookbook::Cable

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

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of Cable.



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/lookbook/cable/cable.rb', line 9

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)



7
8
9
# File 'lib/lookbook/cable/cable.rb', line 7

def engine_mount_path
  @engine_mount_path
end

#loggerObject (readonly)



7
8
9
# File 'lib/lookbook/cable/cable.rb', line 7

def logger
  @logger
end

#serverObject (readonly)



7
8
9
# File 'lib/lookbook/cable/cable.rb', line 7

def server
  @server
end

Instance Method Details

#broadcast(message, payload = nil) ⇒ Object



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

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

#full_mount_pathObject



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

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

#mount_pathObject



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

def mount_path
  "/cable"
end

#mountable?Boolean Also known as: mounted?

Returns:

  • (Boolean)


36
37
38
# File 'lib/lookbook/cable/cable.rb', line 36

def mountable?
  true
end