Sha256: 0bb06245a2636f57796f249021fec1cc3360befe976a25913c1113a2769215f3

Contents?: true

Size: 912 Bytes

Versions: 9

Compression:

Stored size: 912 Bytes

Contents

# frozen_string_literal: true

module StatsD::Instrument::Backends
  # The capture backend is used to capture the metrics that are collected, so you can
  # run assertions on them.
  #
  # @!attribute collected_metrics [r]
  #   @return [Array<StatsD::Instrument::Metric>] The list of metrics that were collected.
  # @see StatsD::Instrument::Assertions
  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
end

Version data entries

9 entries across 9 versions & 1 rubygems

Version Path
statsd-instrument-2.9.2 lib/statsd/instrument/backends/capture_backend.rb
statsd-instrument-2.9.1 lib/statsd/instrument/backends/capture_backend.rb
statsd-instrument-2.9.0 lib/statsd/instrument/backends/capture_backend.rb
statsd-instrument-2.8.0 lib/statsd/instrument/backends/capture_backend.rb
statsd-instrument-2.7.1 lib/statsd/instrument/backends/capture_backend.rb
statsd-instrument-2.7.0 lib/statsd/instrument/backends/capture_backend.rb
statsd-instrument-2.6.0 lib/statsd/instrument/backends/capture_backend.rb
statsd-instrument-2.5.1 lib/statsd/instrument/backends/capture_backend.rb
statsd-instrument-2.5.0 lib/statsd/instrument/backends/capture_backend.rb