Class: Hotwire::Spark::FileWatcher
- Inherits:
-
Object
- Object
- Hotwire::Spark::FileWatcher
- Defined in:
- lib/hotwire/spark/file_watcher.rb
Instance Method Summary collapse
-
#initialize ⇒ FileWatcher
constructor
A new instance of FileWatcher.
- #monitor(paths, &callback) ⇒ Object
- #start ⇒ Object
Constructor Details
#initialize ⇒ FileWatcher
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[(path)] << callback end end |
#start ⇒ Object
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 |