Sha256: fb0e2daa4e9e4c2226e17ab8bc5c35a97617b3e4a14f0a72af8efad26f4fee94
Contents?: true
Size: 1.41 KB
Versions: 2
Compression:
Stored size: 1.41 KB
Contents
module God class Condition < Behavior # Generate a Condition of the given kind. The proper class if found by camel casing the # kind (which is given as an underscored symbol). # +kind+ is the underscored symbol representing the class (e.g. foo_bar for God::Conditions::FooBar) def self.generate(kind) sym = kind.to_s.capitalize.gsub(/_(.)/){$1.upcase}.intern cond = God::Conditions.const_get(sym).new unless cond.kind_of?(PollCondition) || cond.kind_of?(EventCondition) abort "Condition '#{cond.class.name}' must subclass either God::PollCondition or God::EventCondition" end cond rescue NameError raise NoSuchConditionError.new("No Condition found with the class name God::Conditions::#{sym}") end end class PollCondition < Condition # all poll conditions can specify a poll interval attr_accessor :interval # Override this method in your Conditions (optional) def before end # Override this method in your Conditions (mandatory) # # Return true if the test passes (everything is ok) # Return false otherwise def test raise AbstractMethodNotOverriddenError.new("Condition#test must be overridden in subclasses") end # Override this method in your Conditions (optional) def after end end class EventCondition < Condition def register end end end
Version data entries
2 entries across 2 versions & 1 rubygems
Version | Path |
---|---|
god-0.2.0 | lib/god/condition.rb |
god-0.1.0 | lib/god/condition.rb |