class Expri::MetricSet

Public Class Methods

new(options={}) click to toggle source
# File lib/expri/metric_set.rb, line 7
def initialize(options={})
  @options = { :destroy_extras => true }.merge(options)
end

Public Instance Methods

metric(name, attributes={}, options={}) click to toggle source
# File lib/expri/metric_set.rb, line 3
def metric(name, attributes={}, options={})
  @metrics << Metric.new(name, attributes, @options.merge(options))
end
run(&block) click to toggle source
# File lib/expri/metric_set.rb, line 11
def run(&block)
  puts "run options=#{@options}" if @options[:verbose]
  cache_current

  @metrics = []
  instance_eval(&block)
  @metrics.each do |metric|
    metric.put
  end

  destroy_extras
end

Private Instance Methods

cache_current() click to toggle source
# File lib/expri/metric_set.rb, line 26
def cache_current
  @current_metrics = Metric.list
end
destroy_extras() click to toggle source
# File lib/expri/metric_set.rb, line 30
def destroy_extras
  extra_metrics = @current_metrics - @metrics.map(&:name)
  puts "check_extras extras=#{extra_metrics}" if @options[:verbose]
  if @options[:destroy_extras]
    extra_metrics.each do |metric|
      metric = Metric.new(metric, {}, @options)
      metric.destroy
    end
  end
end