Class: God::Condition
Direct Known Subclasses
Instance Attribute Summary collapse
-
#info ⇒ Object
Returns the value of attribute info.
-
#notify ⇒ Object
Returns the value of attribute notify.
-
#phase ⇒ Object
Returns the value of attribute phase.
-
#transition ⇒ Object
Returns the value of attribute transition.
Attributes inherited from Behavior
Class Method Summary collapse
-
.generate(kind, watch) ⇒ Object
Generate a Condition of the given kind.
- .valid?(condition) ⇒ Boolean
Instance Method Summary collapse
-
#friendly_name ⇒ Object
Construct the friendly name of this Condition, looks like:.
Methods inherited from Behavior
#after_restart, #after_start, #after_stop, #before_restart, #before_start, #before_stop, #valid?
Methods included from Configurable
#base_name, complain, #complain, #prepare, #reset, #valid?
Instance Attribute Details
#info ⇒ Object
Returns the value of attribute info.
4 5 6 |
# File 'lib/god/condition.rb', line 4 def info @info end |
#notify ⇒ Object
Returns the value of attribute notify.
4 5 6 |
# File 'lib/god/condition.rb', line 4 def notify @notify end |
#phase ⇒ Object
Returns the value of attribute phase.
4 5 6 |
# File 'lib/god/condition.rb', line 4 def phase @phase end |
#transition ⇒ Object
Returns the value of attribute transition.
4 5 6 |
# File 'lib/god/condition.rb', line 4 def transition @transition end |
Class Method Details
.generate(kind, watch) ⇒ Object
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)
9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 |
# File 'lib/god/condition.rb', line 9 def self.generate(kind, watch) sym = kind.to_s.capitalize.gsub(/_(.)/){$1.upcase}.intern c = God::Conditions.const_get(sym).new unless c.kind_of?(PollCondition) || c.kind_of?(EventCondition) || c.kind_of?(TriggerCondition) abort "Condition '#{c.class.name}' must subclass God::PollCondition, God::EventCondition, or God::TriggerCondition" end if !EventHandler.loaded? && c.kind_of?(EventCondition) abort "Condition '#{c.class.name}' requires an event system but none has been loaded" end c.watch = watch c rescue NameError raise NoSuchConditionError.new("No Condition found with the class name God::Conditions::#{sym}") end |
.valid?(condition) ⇒ Boolean
27 28 29 30 31 32 33 34 35 36 37 |
# File 'lib/god/condition.rb', line 27 def self.valid?(condition) valid = true if condition.notify begin Contact.normalize(condition.notify) rescue ArgumentError => e valid &= Configurable.complain("Attribute 'notify' " + e., condition) end end valid end |
Instance Method Details
#friendly_name ⇒ Object
Construct the friendly name of this Condition, looks like:
Condition FooBar on Watch 'baz'
42 43 44 |
# File 'lib/god/condition.rb', line 42 def friendly_name "Condition #{self.class.name.split('::').last} on Watch '#{self.watch.name}'" end |