Class: Tidings::Watcher

Inherits:
Object
  • Object
show all
Defined in:
lib/tidings/watcher.rb

Instance Method Summary collapse

Constructor Details

#initialize(path, processor) ⇒ Watcher

Returns a new instance of Watcher.



3
4
5
# File 'lib/tidings/watcher.rb', line 3

def initialize(path, processor)
  @path, @processor, @pid = path, processor, nil
end

Instance Method Details

#startObject



7
8
9
10
11
12
13
# File 'lib/tidings/watcher.rb', line 7

def start
  Signal.trap("SIGINT") { stop }
  @pid = fork { watch }
  Tidings.log("Tidings running on PID: #{@pid}")
  Process.wait
  Tidings.log("Tidings stopped running")
end

#stopObject



15
16
17
# File 'lib/tidings/watcher.rb', line 15

def stop
  Process.kill("KILL", @pid)
end

#watchObject



20
21
22
# File 'lib/tidings/watcher.rb', line 20

def watch
  FSEvent.watch(@path, @processor)
end