Class: Lookbook::Websocket
- Inherits:
-
Object
- Object
- Lookbook::Websocket
- Defined in:
- lib/lookbook/websocket.rb
Instance Attribute Summary collapse
-
#engine_mount_path ⇒ Object
readonly
Returns the value of attribute engine_mount_path.
-
#logger ⇒ Object
readonly
Returns the value of attribute logger.
-
#server ⇒ Object
readonly
Returns the value of attribute server.
Class Method Summary collapse
Instance Method Summary collapse
- #broadcast(message, payload = nil) ⇒ Object
- #full_mount_path ⇒ Object
-
#initialize(engine_mount_path, logger: Lookbook.logger) ⇒ Websocket
constructor
A new instance of Websocket.
- #mount_path ⇒ Object
- #mountable? ⇒ Boolean (also: #mounted?)
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_path ⇒ Object (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 |
#logger ⇒ Object (readonly)
Returns the value of attribute logger.
3 4 5 |
# File 'lib/lookbook/websocket.rb', line 3 def logger @logger end |
#server ⇒ Object (readonly)
Returns the value of attribute server.
3 4 5 |
# File 'lib/lookbook/websocket.rb', line 3 def server @server end |
Class Method Details
.noop ⇒ Object
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(, payload = nil) logger.debug .to_s server.broadcast(.to_s, payload.to_h) end |
#full_mount_path ⇒ Object
28 29 30 |
# File 'lib/lookbook/websocket.rb', line 28 def full_mount_path "#{engine_mount_path}/#{mount_path}".gsub("//", "/") end |
#mount_path ⇒ Object
24 25 26 |
# File 'lib/lookbook/websocket.rb', line 24 def mount_path "/cable" end |
#mountable? ⇒ Boolean Also known as: mounted?
32 33 34 |
# File 'lib/lookbook/websocket.rb', line 32 def mountable? true end |