Class: Listen::Adapter::Darwin
- Defined in:
- lib/listen/adapter/darwin.rb
Overview
Adapter implementation for Mac OS X FSEvents
.
Constant Summary
Constants inherited from Base
Instance Attribute Summary
Attributes inherited from Base
Class Method Summary collapse
Instance Method Summary collapse
- #_changes_path(changes) ⇒ Object private
-
#_init_worker ⇒ Object
private
Initializes a FSEvent worker and adds a watcher for each directory listened.
-
#initialize(listener) ⇒ Darwin
constructor
A new instance of Darwin.
- #start ⇒ Object
Methods inherited from Base
#_directories_path, #_latency, #_notify_change
Constructor Details
#initialize(listener) ⇒ Darwin
Returns a new instance of Darwin.
12 13 14 15 |
# File 'lib/listen/adapter/darwin.rb', line 12 def initialize(listener) require 'rb-fsevent' super end |
Class Method Details
.usable? ⇒ Boolean
8 9 10 |
# File 'lib/listen/adapter/darwin.rb', line 8 def self.usable? RbConfig::CONFIG['target_os'] =~ /darwin(1.+)?$/i end |
Instance Method Details
#_changes_path(changes) ⇒ Object (private)
35 36 37 38 39 40 |
# File 'lib/listen/adapter/darwin.rb', line 35 def _changes_path(changes) changes.map do |path| path.sub!(/\/$/, '') Pathname.new(path) end end |
#_init_worker ⇒ Object (private)
Initializes a FSEvent worker and adds a watcher for each directory listened.
27 28 29 30 31 32 33 |
# File 'lib/listen/adapter/darwin.rb', line 27 def _init_worker FSEvent.new.tap do |worker| worker.watch(_directories_path, latency: _latency) do |changes| _changes_path(changes).each { |path| _notify_change(path, type: 'Dir') } end end end |
#start ⇒ Object
17 18 19 20 |
# File 'lib/listen/adapter/darwin.rb', line 17 def start worker = _init_worker worker.run end |