Class: Listen::Adapter::Darwin

Inherits:
Base
  • Object
show all
Defined in:
lib/listen/adapter/darwin.rb

Overview

Adapter implementation for Mac OS X FSEvents.

Constant Summary collapse

OS_REGEXP =
/darwin(1.+)?$/i
DEFAULTS =

The default delay between checking for changes.

{ latency: 0.1 }

Instance Attribute Summary

Attributes inherited from Base

#options

Instance Method Summary collapse

Methods inherited from Base

_log, #_log, #_log_exception, #_queue_change, #configure, #initialize, local_fs?, #start, usable?

Constructor Details

This class inherits a constructor from Listen::Adapter::Base

Instance Method Details

#_configure(dir, &callback) ⇒ Object (private)

NOTE: each directory gets a DIFFERENT callback!



16
17
18
19
20
21
22
23
24
# File 'lib/listen/adapter/darwin.rb', line 16

def _configure(dir, &callback)
  require 'rb-fsevent'
  opts = { latency: options.latency }

  @workers ||= Queue.new
  @workers << FSEvent.new.tap do |worker|
    worker.watch(dir.to_s, opts, &callback)
  end
end

#_process_event(dir, event) ⇒ Object (private)



42
43
44
45
46
47
48
49
50
# File 'lib/listen/adapter/darwin.rb', line 42

def _process_event(dir, event)
  event.each do |path|
    new_path = Pathname.new(path.sub(/\/$/, ''))
    _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

#_runObject (private)

NOTE: _run is called within a thread, so run every other worker in it's own thread



28
29
30
31
32
33
34
35
36
37
38
39
40
# File 'lib/listen/adapter/darwin.rb', line 28

def _run
  first = @workers.pop
  until @workers.empty?
    Listen::Internals::ThreadPool.add do
      begin
        @workers.pop.run
      rescue
        _log_exception 'run() in extra thread(s) failed: %s: %s'
      end
    end
  end
  first.run
end