Method: God::Task#transition
- Defined in:
- lib/god/task.rb
#transition(start_states, end_states) ⇒ Object
Define a transition handler which consists of a set of conditions
72 73 74 75 76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 93 94 95 96 97 98 99 100 101 102 103 104 |
# File 'lib/god/task.rb', line 72 def transition(start_states, end_states) # convert end_states into canonical hash form canonical_end_states = canonical_hash_form(end_states) Array(start_states).each do |start_state| # validate start state unless self.valid_states.include?(start_state) abort "Invalid state :#{start_state}. Must be one of the symbols #{self.valid_states.map{|x| ":#{x}"}.join(', ')}" end # create a new metric to hold the watch, end states, and conditions m = Metric.new(self, canonical_end_states) if block_given? # let the config file define some conditions on the metric yield(m) else # add an :always condition if no block m.condition(:always) do |c| c.what = true end end # populate the condition -> metric directory m.conditions.each do |c| self.directory[c] = m end # record the metric self.metrics[start_state] ||= [] self.metrics[start_state] << m end end |