class SassListen::Adapter::Darwin
Adapter implementation for Mac OS X ‘FSEvents`.
def self.usable?
def self.usable? require 'rb-fsevent' darwin_version = RbConfig::CONFIG['target_os'][OS_REGEXP, :major_version] or return false return true if darwin_version.to_i >= 13 # darwin13 is OS X 10.9 return true if Gem::Version.new(FSEvent::VERSION) <= Gem::Version.new('0.9.4') Kernel.warn INCOMPATIBLE_GEM_VERSION false end
def _configure(dir, &callback)
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
def _process_event(dir, event)
def _process_event(dir, event) _log :debug, "fsevent: processing event: #{event.inspect}" 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
def _run
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
def _run_worker(worker)
def _run_worker(worker) _log :debug, "fsevent: running worker: #{worker.inspect}" worker.run rescue _log_exception 'fsevent: running worker failed: %s:%s called from: %s', caller end
def _run_workers_in_background(workers)
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 SassListen::Internals::ThreadPool.add { _run_worker(worker) } end end
def _to_array(queue)
def _to_array(queue) workers = [] workers << queue.pop until queue.empty? workers end