Class: Vagrant::Syncer::Listeners::FSEvents

Inherits:
Object
  • Object
show all
Defined in:
lib/syncer/listeners/fsevents.rb

Instance Method Summary collapse

Constructor Details

#initialize(paths, excludes, settings, callback) ⇒ FSEvents

Returns a new instance of FSEvents.



8
9
10
11
12
13
# File 'lib/syncer/listeners/fsevents.rb', line 8

def initialize(paths, excludes, settings, callback)
  @paths = paths
  @settings = settings.merge!(no_defer: false)
  @callback = callback
  # rb-fsevent does not support excludes.
end

Instance Method Details

#runObject



15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/syncer/listeners/fsevents.rb', line 15

def run
  changes = Queue.new
  fsevent = FSEvent.new
  fsevent.watch @paths, @settings do |paths|
    paths.each { |path| changes << path }
  end
  Thread.new { fsevent.run }

  loop do
    directories = Set.new
    change = changes.pop
    directories << change  unless change.nil?
    @callback.call(directories.to_a)  unless directories.empty?
  end
end