class Listen::Adapter::BSD

Constants

BUNDLER_DECLARE_GEM
DEFAULTS
OS_REGEXP

Public Class Methods

usable?() click to toggle source
Calls superclass method Listen::Adapter::Base::usable?
# File lib/listen/adapter/bsd.rb, line 31
def self.usable?
  return false unless super
  require 'rb-kqueue'
  require 'find'
  true
rescue LoadError
  Kernel.warn BUNDLER_DECLARE_GEM
  false
end

Private Instance Methods

_change(event_flags) click to toggle source
# File lib/listen/adapter/bsd.rb, line 73
def _change(event_flags)
  { modified: [:attrib, :extend],
    added:    [:write],
    removed:  [:rename, :delete] }.each do |change, flags|
    return change unless (flags & event_flags).empty?
  end
  nil
end
_configure(directory, &callback) click to toggle source
# File lib/listen/adapter/bsd.rb, line 43
def _configure(directory, &callback)
  @worker ||= KQueue::Queue.new
  @callback = callback
  # use Record to make a snapshot of dir, so we
  # can detect new files
  _find(directory.to_s) { |path| _watch_file(path, @worker) }
end
_event_path(event) click to toggle source
# File lib/listen/adapter/bsd.rb, line 82
def _event_path(event)
  Pathname.new(event.watcher.path)
end
_find(*paths, &block) click to toggle source

Quick rubocop workaround

# File lib/listen/adapter/bsd.rb, line 102
def _find(*paths, &block)
  Find.send(:find, *paths, &block)
end
_process_event(dir, event) click to toggle source
# File lib/listen/adapter/bsd.rb, line 55
def _process_event(dir, event)
  full_path = _event_path(event)
  if full_path.directory?
    # Force dir content tracking to kick in, or we won't have
    # names of added files
    _queue_change(:dir, dir, '.', recursive: true)
  elsif full_path.exist?
    path = full_path.relative_path_from(dir)
    _queue_change(:file, dir, path.to_s, change: _change(event.flags))
  end

  # If it is a directory, and it has a write flag, it means a
  # file has been added so find out which and deal with it.
  # No need to check for removed files, kqueue will forget them
  # when the vfs does.
  _watch_for_new_file(event) if full_path.directory?
end
_run() click to toggle source
# File lib/listen/adapter/bsd.rb, line 51
def _run
  @worker.run
end
_watch_file(path, queue) click to toggle source
# File lib/listen/adapter/bsd.rb, line 95
def _watch_file(path, queue)
  queue.watch_file(path, *options.events, &@callback)
rescue Errno::ENOENT => e
  Listen.logger.warn "kqueue: watch file failed: #{e.message}"
end
_watch_for_new_file(event) click to toggle source
# File lib/listen/adapter/bsd.rb, line 86
def _watch_for_new_file(event)
  queue = event.watcher.queue
  _find(_event_path(event).to_s) do |file_path|
    unless queue.watchers.find { |_, v| v.path == file_path.to_s }
      _watch_file(file_path, queue)
    end
  end
end