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)
8 sym = kind.to_s.capitalize.gsub(/_(.)/){$1.upcase}.intern
9 cond = God::Conditions.const_get(sym).new
11 unless cond.kind_of?(PollCondition) || cond.kind_of?(EventCondition)
12 abort "Condition '#{cond.class.name}' must subclass either God::PollCondition or God::EventCondition"
17 raise NoSuchConditionError.new("No Condition found with the class name God::Conditions::#{sym}")
21 class PollCondition < Condition
22 # all poll conditions can specify a poll interval
23 attr_accessor :interval
25 # Override this method in your Conditions (optional)
29 # Override this method in your Conditions (mandatory)
31 # Return true if the test passes (everything is ok)
32 # Return false otherwise
34 raise AbstractMethodNotOverriddenError.new("Condition#test must be overridden in subclasses")
37 # Override this method in your Conditions (optional)
42 class EventCondition < Condition