Class: DDMetrics::Metric

Inherits:
Object
  • Object
show all
Includes:
Enumerable
Defined in:
lib/ddmetrics/metric.rb

Direct Known Subclasses

Counter, Summary

Instance Method Summary collapse

Constructor Details

#initializeMetric

Returns a new instance of Metric.



7
8
9
# File 'lib/ddmetrics/metric.rb', line 7

def initialize
  @basic_metrics = {}
end

Instance Method Details

#basic_metric_for(label, basic_class) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



26
27
28
# File 'lib/ddmetrics/metric.rb', line 26

def basic_metric_for(label, basic_class)
  @basic_metrics.fetch(label) { @basic_metrics[label] = basic_class.new }
end

#eachObject



19
20
21
22
23
# File 'lib/ddmetrics/metric.rb', line 19

def each
  @basic_metrics.each_key do |label|
    yield(label, get(label))
  end
end

#get(label) ⇒ Object



11
12
13
# File 'lib/ddmetrics/metric.rb', line 11

def get(label)
  basic_metric_for(label, BasicCounter)
end

#labelsObject



15
16
17
# File 'lib/ddmetrics/metric.rb', line 15

def labels
  @basic_metrics.keys
end

#validate_label(label) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Raises:

  • (ArgumentError)


31
32
33
34
# File 'lib/ddmetrics/metric.rb', line 31

def validate_label(label)
  return if label.is_a?(Hash)
  raise ArgumentError, 'label argument must be a hash'
end