change File.open {}.read to File.read
[god.git] / lib / god / conditions / process_exits.rb
blobcf194e92e69f71649c7e93da75042ddc714c6a17
1 module God
2   module Conditions
3     
4     class ProcessExits < EventCondition
5       def valid?
6         valid = true
7         valid &= complain("You must specify the 'pid_file' attribute on the Watch for :process_exits") if self.watch.pid_file.nil?
8         valid
9       end
10     
11       def register
12         pid = File.read(self.watch.pid_file).strip.to_i
13         
14         EventHandler.register(pid, :proc_exit) do
15           Hub.trigger(self)
16         end
17       end
18       
19       def deregister
20         pid = File.read(self.watch.pid_file).strip.to_i
21         EventHandler.deregister(pid, :proc_exit)
22       end
23     end
24     
25   end
26 end