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
11 unless c.kind_of?(PollCondition) || c.kind_of?(EventCondition)
12 abort "Condition '#{c.class.name}' must subclass either God::PollCondition or God::EventCondition"
18 raise NoSuchConditionError.new("No Condition found with the class name God::Conditions::#{sym}")
22 class PollCondition < Condition
23 # all poll conditions can specify a poll interval
24 attr_accessor :interval
25 attr_accessor :transition
27 # Override this method in your Conditions (optional)
31 # Override this method in your Conditions (mandatory)
33 # Return true if the test passes (everything is ok)
34 # Return false otherwise
36 raise AbstractMethodNotOverriddenError.new("Condition#test must be overridden in subclasses")
39 # Override this method in your Conditions (optional)
44 class EventCondition < Condition