Class: DDMetrics::Metric
- Inherits:
-
Object
- Object
- DDMetrics::Metric
- Includes:
- Enumerable
- Defined in:
- lib/ddmetrics/metric.rb
Instance Method Summary collapse
- #basic_metric_for(label, basic_class) ⇒ Object private
- #each ⇒ Object
- #get(label) ⇒ Object
-
#initialize ⇒ Metric
constructor
A new instance of Metric.
- #labels ⇒ Object
- #validate_label(label) ⇒ Object private
Constructor Details
#initialize ⇒ Metric
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 |
#each ⇒ Object
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 |
#labels ⇒ Object
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.
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 |