class Lookbook::FileWatcher

def init_listener(paths, opts, &block)

def init_listener(paths, opts, &block)
  Listen.to(
    *paths,
    **opts,
    force_polling: force_polling
  ) do |modified, added, removed|
    block.call({modified: modified, added: added, removed: removed})
  end
end

def initialize(force_polling: false)

def initialize(force_polling: false)
  @force_polling = force_polling
  @listeners = []
end

def start

def start
  if listeners.any?
    Lookbook.logger.debug "Starting listeners"
    listeners.each { |l| l.start }
  end
end

def stop

def stop
  if listeners.any?
    Lookbook.logger.debug "Stopping listeners"
    listeners.each { |l| l.stop }
  end
end

def watch(paths, extensions = ".*", opts = nil, &block)

def watch(paths, extensions = ".*", opts = nil, &block)
  paths = PathUtils.normalize_paths(paths)
  if paths.any?
    opts = opts.to_h
    opts[:only] = /\.(#{Array(extensions).join("|")})$/
    listeners << init_listener(paths, opts, &block)
  end
end