class INotify::Notifier

def watch(path, *flags, &callback)

Raises:
  • (SystemCallError) - if the file or directory can't be watched,

Returns:
  • (Watcher) - A Watcher set up to watch this path for these events

Other tags:
    Yieldparam: event - The Event object containing information

Other tags:
    Yield: - A block that will be called

Parameters:
  • flags (Array) -- Which events to watch for
  • path (String) -- The path to the file or directory
def watch(path, *flags, &callback)
  return Watcher.new(self, path, *flags, &callback) unless flags.include?(:recursive)
  Dir.entries(path).each do |d|
    next if d == '.' || d == '..'
    d = File.join(path, d)
    watch(d, *flags, &callback) if File.directory?(d)
  end
  rec_flags = [:create, :moved_to]
  return watch(path, *((flags - [:recursive]) | rec_flags)) do |event|
    callback.call(event) if flags.include?(:all_events) || !(flags & event.flags).empty?
    next if (rec_flags & event.flags).empty? || !event.flags.include?(:isdir)
    watch(event.absolute_name, *flags, &callback)
  end
end