class Adsf::Live::Watcher
Public Class Methods
new(root_dir:)
click to toggle source
# File lib/adsf/live/watcher.rb, line 6 def initialize(root_dir:) unless Pathname.new(root_dir).absolute? raise ArgumentError, 'Watcher#initialize: The root_path argument must be an absolute path' end @root_dir = root_dir end
Public Instance Methods
handle_changes(server, chs)
click to toggle source
# File lib/adsf/live/watcher.rb, line 45 def handle_changes(server, chs) prefix_length = @root_dir.length paths = chs.map { |pa| pa[prefix_length..-1] } server.reload(paths) end
start()
click to toggle source
# File lib/adsf/live/watcher.rb, line 14 def start @server = start_server @listener = start_listener(@server) end
start_listener(server)
click to toggle source
# File lib/adsf/live/watcher.rb, line 31 def start_listener(server) options = { latency: 0.0, wait_for_delay: 0.0, } listener = Listen.to(@root_dir, options) do |ch_mod, ch_add, ch_del| handle_changes(server, [ch_mod, ch_add, ch_del].flatten) end listener.start listener end
start_server()
click to toggle source
# File lib/adsf/live/watcher.rb, line 24 def start_server ::Adsf::Live::WebSocketServer.new( host: '0.0.0.0', port: '35729', ) end
stop()
click to toggle source
# File lib/adsf/live/watcher.rb, line 19 def stop @listener&.stop @server&.stop end