class INotify::Notifier
def watch(path, *flags, &callback)
-
(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 = Dir.new(path) dir.each do |base| d = File.join(path, base) binary_d = d.respond_to?(:force_encoding) ? d.dup.force_encoding('BINARY') : d next if binary_d =~ /\/\.\.?$/ # Current or parent directory watch(d, *flags, &callback) if !RECURSIVE_BLACKLIST.include?(d) && File.directory?(d) end dir.close 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) begin watch(event.absolute_name, *flags, &callback) rescue Errno::ENOENT # If the file has been deleted since the glob was run, we don't want to error out. end end end