3 class Condition < Behavior
4 attr_accessor :transition
6 # Generate a Condition of the given kind. The proper class if found by camel casing the
7 # kind (which is given as an underscored symbol).
8 # +kind+ is the underscored symbol representing the class (e.g. foo_bar for God::Conditions::FooBar)
9 def self.generate(kind, watch)
10 sym = kind.to_s.capitalize.gsub(/_(.)/){$1.upcase}.intern
11 c = God::Conditions.const_get(sym).new
13 unless c.kind_of?(PollCondition) || c.kind_of?(EventCondition) || c.kind_of?(TriggerCondition)
14 abort "Condition '#{c.class.name}' must subclass either God::PollCondition or God::EventCondition"
20 raise NoSuchConditionError.new("No Condition found with the class name God::Conditions::#{sym}")
24 class PollCondition < Condition
25 # all poll conditions can specify a poll interval
26 attr_accessor :interval
28 # Override this method in your Conditions (optional)
32 # Override this method in your Conditions (mandatory)
34 # Return true if the test passes (everything is ok)
35 # Return false otherwise
37 raise AbstractMethodNotOverriddenError.new("PollCondition#test must be overridden in subclasses")
40 # Override this method in your Conditions (optional)
45 class EventCondition < Condition
47 raise AbstractMethodNotOverriddenError.new("EventCondition#register must be overridden in subclasses")
51 raise AbstractMethodNotOverriddenError.new("EventCondition#deregister must be overridden in subclasses")
55 class TriggerCondition < Condition
56 def process(event, payload)
57 raise AbstractMethodNotOverriddenError.new("TriggerCondition#process must be overridden in subclasses")
65 Trigger.register(self)
69 Trigger.deregister(self)