fix process#alive? to not raise on no such file
[god.git] / lib / god / conditions / tries.rb
blob176224a2195fec5a9e6590ae1cd23bfbdb494cca
1 module God
2   module Conditions
3     
4     class Tries < PollCondition
5       attr_accessor :times, :within
6       
7       def prepare
8         @timeline = Timeline.new(self.times)
9       end
10     
11       def valid?
12         valid = true
13         valid &= complain("You must specify the 'times' attribute for :tries") if self.times.nil?
14         valid
15       end
16     
17       def test
18         @timeline << Time.now
19         
20         concensus = (@timeline.size == self.times)
21         duration = within.nil? || (@timeline.last - @timeline.first) < self.within
22         
23         if concensus && duration
24           @timeline.clear if within.nil?
25           return true
26         else
27           return false
28         end
29       end
30     end
31     
32   end
33 end