hide kqueue tests from linux
[god.git] / lib / god / condition.rb
blob2217808433ef21ee6b93ec26d81df908c7496046
1 module God
2   
3   class Condition < Behavior
4     # Generate a Condition of the given kind. The proper class if found by camel casing the
5     # kind (which is given as an underscored symbol).
6     #   +kind+ is the underscored symbol representing the class (e.g. foo_bar for God::Conditions::FooBar)
7     def self.generate(kind, watch)
8       sym = kind.to_s.capitalize.gsub(/_(.)/){$1.upcase}.intern
9       c = God::Conditions.const_get(sym).new
10       
11       unless c.kind_of?(PollCondition) || c.kind_of?(EventCondition)
12         abort "Condition '#{c.class.name}' must subclass either God::PollCondition or God::EventCondition" 
13       end
14       
15       c.watch = watch
16       c
17     rescue NameError
18       raise NoSuchConditionError.new("No Condition found with the class name God::Conditions::#{sym}")
19     end
20   end
21   
22   class PollCondition < Condition
23     # all poll conditions can specify a poll interval 
24     attr_accessor :interval
25     attr_accessor :transition
26     
27     # Override this method in your Conditions (optional)
28     def before
29     end
30     
31     # Override this method in your Conditions (mandatory)
32     #
33     # Return true if the test passes (everything is ok)
34     # Return false otherwise
35     def test
36       raise AbstractMethodNotOverriddenError.new("Condition#test must be overridden in subclasses")
37     end
38     
39     # Override this method in your Conditions (optional)
40     def after
41     end
42   end
43   
44   class EventCondition < Condition
45     def register
46       
47     end
48   end
49   
50 end