Class: Vagrant::Syncer::Listeners::INotify

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

Instance Method Summary collapse

Constructor Details

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

Returns a new instance of INotify.



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

def initialize(paths, excludes, settings, callback)
  @paths = paths
  @settings = settings
  @callback = callback
  # rb-inotify does not support excludes.
end

Instance Method Details

#runObject



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

def run
  notifier = ::INotify::Notifier.new

  @paths.each do |path|
    notifier.watch(path, :modify, :create, :delete, :recursive) {}
  end

  loop do
    directories = Set.new
    notifier.read_events.each { |e| directories << e.absolute_name }
    @callback.call(directories.to_a)  unless directories.empty?
  end
end