Class: Hotwire::Spark::FileWatcher

Inherits:
Object
  • Object
show all
Defined in:
lib/hotwire/spark/file_watcher.rb

Instance Method Summary collapse

Constructor Details

#initializeFileWatcher

Returns a new instance of FileWatcher.



4
5
6
# File 'lib/hotwire/spark/file_watcher.rb', line 4

def initialize
  @callbacks_by_path = Hash.new { |hash, key| hash[key] = [] }
end

Instance Method Details

#monitor(paths, &callback) ⇒ Object



8
9
10
11
12
# File 'lib/hotwire/spark/file_watcher.rb', line 8

def monitor(paths, &callback)
  Array(paths).each do |path|
    @callbacks_by_path[expand_path(path)] << callback
  end
end

#startObject



14
15
16
17
18
19
20
# File 'lib/hotwire/spark/file_watcher.rb', line 14

def start
  listener = Listen.to(*paths) do |modified, added, removed|
    process_changed_files modified + added + removed
  end

  listener.start
end