Class: Lookbook::Cable
- Inherits:
-
Object
- Object
- Lookbook::Cable
- Defined in:
- lib/lookbook/cable/cable.rb
Instance Attribute Summary collapse
- #engine_mount_path ⇒ Object readonly
- #logger ⇒ Object readonly
- #server ⇒ Object readonly
Instance Method Summary collapse
- #broadcast(message, payload = nil) ⇒ Object
- #full_mount_path ⇒ Object
-
#initialize(engine_mount_path, logger: Lookbook.logger) ⇒ Cable
constructor
A new instance of Cable.
- #mount_path ⇒ Object
- #mountable? ⇒ Boolean (also: #mounted?)
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_path ⇒ Object (readonly)
7 8 9 |
# File 'lib/lookbook/cable/cable.rb', line 7 def engine_mount_path @engine_mount_path end |
#logger ⇒ Object (readonly)
7 8 9 |
# File 'lib/lookbook/cable/cable.rb', line 7 def logger @logger end |
#server ⇒ Object (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(, payload = nil) logger.debug .to_s server.broadcast(.to_s, payload.to_h) end |
#full_mount_path ⇒ Object
32 33 34 |
# File 'lib/lookbook/cable/cable.rb', line 32 def full_mount_path "#{engine_mount_path}/#{mount_path}".gsub("//", "/") end |
#mount_path ⇒ Object
28 29 30 |
# File 'lib/lookbook/cable/cable.rb', line 28 def mount_path "/cable" end |
#mountable? ⇒ Boolean Also known as: mounted?
36 37 38 |
# File 'lib/lookbook/cable/cable.rb', line 36 def mountable? true end |