lib/bluepill/condition_watch.rb in bluepill-0.0.1 vs lib/bluepill/condition_watch.rb in bluepill-0.0.2

- old
+ new

@@ -1,8 +1,8 @@ module Bluepill class ConditionWatch - attr_accessor :logger + attr_accessor :logger, :name def initialize(name, options = {}) @name = name @logger = options.delete(:logger) @fires = options.has_key?(:fires) ? [options.delete(:fires)].flatten : [:restart] @@ -24,29 +24,30 @@ [] end def record_value(value) # TODO: record value in ProcessStatistics - self.logger.info(self.to_s) if self.logger @history[@history_index] = [value, @process_condition.check(value)] @history_index = (@history_index + 1) % @history.size + self.logger.info(self.to_s) end def clear_history! @last_ran_at = nil @history = Array.new(@times[1]) @history_index = 0 end def fired? - @history.select {|v| !v[1] }.size >= @times[0] + @history.select {|v| v && !v[1]}.size >= @times[0] end def to_s # TODO: this will be out of order because of the way history values are assigned # use (@history[(@history_index - 1)..1] + @history[0..(@history_index - 1)]). # collect {|v| "#{v[0]}#{v[1] ? '' : '*'}"}.join(", ") # but that's gross so... it's gonna be out of order till we figure out a better way to get it in order - @history.collect {|v| "#{v[0]}#{v[1] ? '' : '*'}"}.join(", ") + data = @history.collect {|v| "#{v[0]}#{v[1] ? '' : '*'}" if v}.compact.join(", ") + "#{@name}: [#{data}]" end end end \ No newline at end of file