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?
return false
        require 'rb-fsevent'
        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

        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

NOTE: each directory gets a DIFFERENT callback!

# File lib/listen/adapter/darwin.rb, line 40
def _configure(dir, &callback)
  opts = { latency: options.latency }

  @workers ||= ::Queue.new
  @workers << FSEvent.new.tap do |worker|
    _log :debug, "fsevent: watching: #{dir.to_s.inspect}"
    worker.watch(dir.to_s, opts, &callback)
  end
end
_process_event(dir, event) click to toggle source
# File lib/listen/adapter/darwin.rb, line 59
def _process_event(dir, event)
  _log :debug, "fsevent: processing event: #{event.inspect}"
  event.each do |path|
    new_path = Pathname.new(path.sub(%r{\/$}, ''))
    _log :debug, "fsevent: #{new_path}"
    # TODO: does this preserve symlinks?
    rel_path = new_path.relative_path_from(dir).to_s
    _queue_change(:dir, dir, rel_path, recursive: true)
  end
end
_run() click to toggle source
# File lib/listen/adapter/darwin.rb, line 50
def _run
  first = @workers.pop

  # NOTE: _run is called within a thread, so run every other
  # worker in it's own thread
  _run_workers_in_background(_to_array(@workers))
  _run_worker(first)
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
_run_workers_in_background(workers) click to toggle source
# File lib/listen/adapter/darwin.rb, line 78
def _run_workers_in_background(workers)
  workers.each do |worker|
    # NOTE: while passing local variables to the block below is not
    # thread safe, using 'worker' from the enumerator above is ok
    Listen::Internals::ThreadPool.add { _run_worker(worker) }
  end
end
_to_array(queue) click to toggle source
# File lib/listen/adapter/darwin.rb, line 86
def _to_array(queue)
  workers = []
  workers << queue.pop until queue.empty?
  workers
end