class Listen::Adapter::Darwin

Adapter implementation for Mac OS X `FSEvents`.

Constants

DEFAULTS

The default delay between checking for changes.

INCOMPATIBLE_GEM_VERSION
OS_REGEXP

Public Class Methods

usable?() click to toggle source
# File lib/listen/adapter/darwin.rb, line 24
def self.usable?
  version = RbConfig::CONFIG['target_os'][OS_REGEXP, :major_version]
  return false unless version
  return true if version.to_i >= 13 # darwin13 is OS X 10.9

  require 'rb-fsevent'
  fsevent_version = Gem::Version.new(FSEvent::VERSION)
  return true if fsevent_version <= Gem::Version.new('0.9.4')
  Kernel.warn INCOMPATIBLE_GEM_VERSION
  false
end

Private Instance Methods

_configure(dir, &callback) click to toggle source
# File lib/listen/adapter/darwin.rb, line 38
def _configure(dir, &callback)
  @callbacks[dir] = callback
end
_process_changes(dirs) click to toggle source
# File lib/listen/adapter/darwin.rb, line 51
def _process_changes(dirs)
  dirs.each do |dir|
    dir = Pathname.new(dir.sub(%r{\/$}, ''))

    @callbacks.each do |watched_dir, callback|
      if watched_dir.eql?(dir) || Listen::Directory.ascendant_of?(watched_dir, dir)
        callback.call(dir)
      end
    end
  end
end
_process_event(dir, path) click to toggle source
# File lib/listen/adapter/darwin.rb, line 63
def _process_event(dir, path)
  _log(:debug) { "fsevent: processing path: #{path.inspect}" }
  # TODO: does this preserve symlinks?
  rel_path = path.relative_path_from(dir).to_s
  _queue_change(:dir, dir, rel_path, recursive: true)
end
_run() click to toggle source
# File lib/listen/adapter/darwin.rb, line 42
def _run
  require 'rb-fsevent'
  worker = FSEvent.new
  dirs_to_watch = @callbacks.keys.map(&:to_s)
  _log(:info) { "fsevent: watching: #{dirs_to_watch.inspect}" }
  worker.watch(dirs_to_watch, { latency: options.latency }, &method(:_process_changes))
  Listen::Internals::ThreadPool.add { _run_worker(worker) }
end
_run_worker(worker) click to toggle source
# File lib/listen/adapter/darwin.rb, line 70
def _run_worker(worker)
  _log(:debug) { "fsevent: running worker: #{worker.inspect}" }
  worker.run
rescue
  format_string = 'fsevent: running worker failed: %s:%s called from: %s'
  _log_exception format_string, caller
end