class Attractor::Watcher

functionality for watching file system changes

Public Class Methods

new(file_prefix, ignores, callback) click to toggle source
# File lib/attractor/watcher.rb, line 8
def initialize(file_prefix, ignores, callback)
  @file_prefix = file_prefix
  @callback = callback
  @ignores = ignores.split(",").map(&:strip)
end

Public Instance Methods

watch() click to toggle source
# File lib/attractor/watcher.rb, line 14
def watch
  @callback.call
  ignore = @ignores + [/^attractor_output/]

  listener = Listen.to(File.absolute_path(@file_prefix), ignore: ignore) do |modified, _added, _removed|
    if modified
      puts "#{modified.map(&:to_s).join(", ")} modified, recalculating..."
      @callback.call
    end
  end
  listener.start
  sleep
end