lib/lookbook/engine.rb in lookbook-1.0.2 vs lib/lookbook/engine.rb in lookbook-1.0.3
- old
+ new
@@ -101,17 +101,15 @@
if Gem::Version.new(Rails.version) >= Gem::Version.new("6.1.3.1")
# Rails.application.server is only available for newer Rails versions
Rails.application.server do
init_listeners
- Lookbook::Engine.init_websocket
end
else
# Fallback for older Rails versions - don't start listeners if running in a rake task.
unless Lookbook::Engine.prevent_listening?
init_listeners
- Lookbook::Engine.init_websocket
end
end
if config.lookbook.runtime_parsing
Lookbook::Engine.parser.parse
@@ -168,36 +166,37 @@
run_hooks(:after_change, changes)
end
register_listener(page_listener)
end
- def init_websocket
+ def websocket
config = Lookbook.config
+ return @websocket unless @websocket.nil?
return unless config.auto_refresh == true
Lookbook.logger.info "Initializing websocket"
cable = ActionCable::Server::Configuration.new
cable.cable = {adapter: "async"}.with_indifferent_access
cable.mount_path = config.cable_mount_path
cable.connection_class = -> { Lookbook::Connection }
cable.logger = config.cable_logger
- @websocket = if Gem::Version.new(Rails.version) >= Gem::Version.new(6.0)
+ @websocket ||= if Gem::Version.new(Rails.version) >= Gem::Version.new(6.0)
ActionCable::Server::Base.new(config: cable)
else
ws = ActionCable::Server::Base.new
ws.config = cable
ws
end
end
def websocket_mount_path
- "#{mounted_path}#{config.lookbook.cable_mount_path}" if websocket
+ "#{mounted_path}#{config.lookbook.cable_mount_path}" if websocket?
end
def websocket?
- !!websocket
+ websocket.present?
end
def mounted_path
Lookbook::Engine.routes.find_script_name({})
end
@@ -252,9 +251,9 @@
else
false
end
end
- attr_reader :preview_controller, :websocket
+ attr_reader :preview_controller
end
end
end