Sha256: b33fd5f7749434a2ef3791a7c442c771bc93a69dabf6903bcaca5f57710ee2d8

Contents?: true

Size: 561 Bytes

Versions: 30

Compression:

Stored size: 561 Bytes

Contents

# frozen_string_literal: true

module Attractor
  # functionality for watching file system changes
  class Watcher
    def initialize(file_prefix, callback)
      @file_prefix = file_prefix
      @callback = callback
    end

    def watch
      @callback.call

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

Version data entries

30 entries across 30 versions & 1 rubygems

Version Path
attractor-0.4.2 lib/attractor/watcher.rb
attractor-0.4.1 lib/attractor/watcher.rb
attractor-0.4.0 lib/attractor/watcher.rb
attractor-0.3.4 lib/attractor/watcher.rb
attractor-0.3.3 lib/attractor/watcher.rb
attractor-0.3.2 lib/attractor/watcher.rb
attractor-0.3.1 lib/attractor/watcher.rb
attractor-0.3.0 lib/attractor/watcher.rb
attractor-0.2.1 lib/attractor/watcher.rb
attractor-0.2.0 lib/attractor/watcher.rb