1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37
|
# frozen_string_literal: true
module DDMetrics
class Metric
include Enumerable
def initialize
@basic_metrics = {}
end
def get(label)
basic_metric_for(label, BasicCounter)
end
def labels
@basic_metrics.keys
end
def each
@basic_metrics.each_key do |label|
yield(label, get(label))
end
end
# @api private
def basic_metric_for(label, basic_class)
@basic_metrics.fetch(label) { @basic_metrics[label] = basic_class.new }
end
# @api private
def validate_label(label)
return if label.is_a?(Hash)
raise ArgumentError, 'label argument must be a hash'
end
end
end
|