Class: God::Condition

Inherits:
Behavior show all
Defined in:
lib/god/condition.rb

Direct Known Subclasses

EventCondition, PollCondition, TriggerCondition

Instance Attribute Summary collapse

Attributes inherited from Behavior

#watch

Class Method Summary collapse

Instance Method Summary collapse

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

#infoObject

Returns the value of attribute info.



4
5
6
# File 'lib/god/condition.rb', line 4

def info
  @info
end

#notifyObject

Returns the value of attribute notify.



4
5
6
# File 'lib/god/condition.rb', line 4

def notify
  @notify
end

#phaseObject

Returns the value of attribute phase.



4
5
6
# File 'lib/god/condition.rb', line 4

def phase
  @phase
end

#transitionObject

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

Returns:



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.message, condition)
    end
  end
  valid
end

Instance Method Details

#friendly_nameObject

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