Class: StatsD::Instrument::Backends::CaptureBackend

Inherits:
StatsD::Instrument::Backend show all
Defined in:
lib/statsd/instrument/backends/capture_backend.rb

Overview

The capture backend is used to capture the metrics that are collected, so you can run assertions on them.

See Also:

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeCaptureBackend

Returns a new instance of CaptureBackend.



14
15
16
# File 'lib/statsd/instrument/backends/capture_backend.rb', line 14

def initialize
  reset
end

Instance Attribute Details

#collected_metricsArray<StatsD::Instrument::Metric> (readonly)

Returns The list of metrics that were collected.

Returns:



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/statsd/instrument/backends/capture_backend.rb', line 10

class CaptureBackend < StatsD::Instrument::Backend
  attr_reader :collected_metrics
  attr_accessor :parent

  def initialize
    reset
  end

  # Adds a metric to the ist of collected metrics.
  # @param metric [StatsD::Instrument::Metric]  The metric to collect.
  # @return [void]
  def collect_metric(metric)
    parent&.collect_metric(metric)
    @collected_metrics << metric
  end

  # Resets the list of collected metrics to an empty list.
  # @return [void]
  def reset
    @collected_metrics = []
  end
end

#parentObject

Returns the value of attribute parent.



12
13
14
# File 'lib/statsd/instrument/backends/capture_backend.rb', line 12

def parent
  @parent
end

Instance Method Details

#collect_metric(metric) ⇒ void

This method returns an undefined value.

Adds a metric to the ist of collected metrics.

Parameters:



21
22
23
24
# File 'lib/statsd/instrument/backends/capture_backend.rb', line 21

def collect_metric(metric)
  parent&.collect_metric(metric)
  @collected_metrics << metric
end

#resetvoid

This method returns an undefined value.

Resets the list of collected metrics to an empty list.



28
29
30
# File 'lib/statsd/instrument/backends/capture_backend.rb', line 28

def reset
  @collected_metrics = []
end