class FseventsToVm::Watch

Public Class Methods

new(*listen_dirs) click to toggle source
# File lib/fsevents_to_vm/watch.rb, line 5
def initialize(*listen_dirs)
  @listen_dirs = listen_dirs
  @fs = FSEvent.new
end

Public Instance Methods

run() { |event| ... } click to toggle source
# File lib/fsevents_to_vm/watch.rb, line 10
def run
  @fs.watch(@listen_dirs, file_events: true) do |files|
    files.each do |file|
      event = build_event(file)
      yield event if event
    end
  end
  @fs.run
end

Private Instance Methods

build_event(filepath) click to toggle source
# File lib/fsevents_to_vm/watch.rb, line 22
def build_event(filepath)
  mtime = Event.format_time(File.stat(filepath).mtime)
  Event.new(filepath, mtime, Time.now)
rescue Errno::ENOENT
  # TODO: handling delete events is tricky due to race conditions with rapid
  # delete/create.
  nil
rescue Errno::ENOTDIR
  # dir structure changed
  nil
end