Class: AutoreloadServer::Watcher
- Inherits:
-
Object
- Object
- AutoreloadServer::Watcher
- Defined in:
- lib/autoreload_server/watcher.rb
Instance Method Summary collapse
-
#initialize(directory, watch_pattern, &callback) ⇒ Watcher
constructor
A new instance of Watcher.
- #start ⇒ Object
- #stop ⇒ Object
Constructor Details
#initialize(directory, watch_pattern, &callback) ⇒ Watcher
Returns a new instance of Watcher.
7 8 9 10 11 |
# File 'lib/autoreload_server/watcher.rb', line 7 def initialize(directory, watch_pattern, &callback) @directory = directory @watch_pattern = watch_pattern @callback = callback end |
Instance Method Details
#start ⇒ Object
13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/autoreload_server/watcher.rb', line 13 def start @listener = Listen.to(@directory) do |modified, added, removed| (modified + added + removed).each do |file| next unless match_file?(file) relative_path = Pathname.new(file).relative_path_from(Pathname.new(@directory)).to_s @callback.call(relative_path) end end @listener.start end |
#stop ⇒ Object
26 27 28 |
# File 'lib/autoreload_server/watcher.rb', line 26 def stop @listener&.stop end |