Class: Tidings::Watcher
- Inherits:
-
Object
- Object
- Tidings::Watcher
- Defined in:
- lib/tidings/watcher.rb
Overview
Starts a file watcher in a separate process.
Instance Method Summary collapse
-
#initialize(path, processor) ⇒ Watcher
constructor
A new instance of Watcher.
- #start ⇒ Object
- #stop ⇒ Object
- #watch ⇒ Object
Constructor Details
#initialize(path, processor) ⇒ Watcher
6 7 8 9 10 |
# File 'lib/tidings/watcher.rb', line 6 def initialize(path, processor) @path = path @processor = processor @pid = nil end |
Instance Method Details
#start ⇒ Object
12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 |
# File 'lib/tidings/watcher.rb', line 12 def start Signal.trap('HUP') { stop } Signal.trap('SIGINT') { stop } @pid = fork do begin watch rescue Exception => e Tidings.log( "Tidings encountered an uncaught exeption: #{e.message}" ) exit end end Tidings.log("Tidings running on PID: #{@pid}") Process.waitpid(@pid) Tidings.log('Tidings stopped running') end |
#stop ⇒ Object
30 31 32 33 |
# File 'lib/tidings/watcher.rb', line 30 def stop Process.kill('KILL', @pid) rescue Errno::ESRCH end |
#watch ⇒ Object
36 37 38 |
# File 'lib/tidings/watcher.rb', line 36 def watch FSEvent.watch(@path, @processor) end |