Sha256: 5387bcb7fc3c43d13da95c2ecb40ebc1451ffd7203488502a34c41eca1a9f5e9

Contents?: true

Size: 494 Bytes

Versions: 1

Compression:

Stored size: 494 Bytes

Contents

# frozen_string_literal: true

module StatsD::Instrument::Helpers
  def capture_statsd_calls(&block)
    mock_backend = StatsD::Instrument::Backends::CaptureBackend.new
    old_backend = StatsD.backend
    StatsD.backend = mock_backend

    block.call
    mock_backend.collected_metrics
  ensure
    if old_backend.is_a?(StatsD::Instrument::Backends::CaptureBackend)
      old_backend.collected_metrics.concat(mock_backend.collected_metrics)
    end

    StatsD.backend = old_backend
  end
end

Version data entries

1 entries across 1 versions & 1 rubygems

Version Path
statsd-instrument-2.4.0 lib/statsd/instrument/helpers.rb