Sha256: f222c26119d9dd215f0eaa12a9f394165512194ecfff6385ff9490486f20c385

Contents?: true

Size: 1.5 KB

Versions: 67

Compression:

Stored size: 1.5 KB

Contents

module God
  
  class Metric
    attr_accessor :watch, :destination, :conditions
    
    def initialize(watch, destination = nil)
      self.watch = watch
      self.destination = destination
      self.conditions = []
    end
    
    # Instantiate a Condition of type +kind+ and pass it into the optional
    # block. Attributes of the condition must be set in the config file
    def condition(kind)
      # create the condition
      begin
        c = Condition.generate(kind, self.watch)
      rescue NoSuchConditionError => e
        abort e.message
      end
      
      # send to block so config can set attributes
      yield(c) if block_given?
      
      # call prepare on the condition
      c.prepare
      
      # test generic and specific validity
      unless Condition.valid?(c) && c.valid?
        abort "Exiting on invalid condition"
      end
      
      # inherit interval from watch if no poll condition specific interval was set
      if c.kind_of?(PollCondition) && !c.interval
        if self.watch.interval
          c.interval = self.watch.interval
        else
          abort "No interval set for Condition '#{c.class.name}' in Watch '#{self.watch.name}', and no default Watch interval from which to inherit"
        end
      end
      
      # remember
      self.conditions << c
    end
    
    def enable
      self.conditions.each do |c|
        self.watch.attach(c)
      end
    end
    
    def disable
      self.conditions.each do |c|
        self.watch.detach(c)
      end
    end
  end
  
end

Version data entries

67 entries across 67 versions & 21 rubygems

Version Path
god-0.9.0 lib/god/metric.rb
olgen-god-0.9.2 lib/god/metric.rb
olgen-god-0.9.1 lib/god/metric.rb
olgen-god-0.9.0 lib/god/metric.rb
god-0.8.0 lib/god/metric.rb
olgen-god-0.8.2 lib/god/metric.rb
olgen-god-0.8.1 lib/god/metric.rb
olgen-god-0.8.0 lib/god/metric.rb
god-0.7.22 lib/god/metric.rb
god-0.7.21 lib/god/metric.rb
god-0.7.20 lib/god/metric.rb
god-0.7.19 lib/god/metric.rb
god-0.7.18 lib/god/metric.rb
god-0.7.17 lib/god/metric.rb
god-0.7.16 lib/god/metric.rb
god-0.7.15 lib/god/metric.rb
god-0.7.14 lib/god/metric.rb
god-0.7.0 lib/god/metric.rb
god-0.7.10 lib/god/metric.rb
god-0.7.11 lib/god/metric.rb