Sha256: 2a5620f59afdb405fdd7d2cb90e939d15d3d4bf7131fe5a7c130dc878f1b5e1d

Contents?: true

Size: 609 Bytes

Versions: 20

Compression:

Stored size: 609 Bytes

Contents

# frozen_string_literal: true

module Nanoc::Telemetry
  class LabelledCounter
    def initialize
      @counters = {}
    end

    def increment(label)
      get(label).increment
    end

    def get(label)
      @counters.fetch(label) { @counters[label] = Counter.new }
    end

    def empty?
      @counters.empty?
    end

    def value(label)
      get(label).value
    end

    def values
      @counters.each_with_object({}) do |(label, counter), res|
        res[label] = counter.value
      end
    end

    def map
      @counters.map { |(label, counter)| yield(label, counter) }
    end
  end
end

Version data entries

20 entries across 20 versions & 1 rubygems

Version Path
nanoc-4.8.14 lib/nanoc/telemetry/labelled_counter.rb
nanoc-4.8.13 lib/nanoc/telemetry/labelled_counter.rb
nanoc-4.8.12 lib/nanoc/telemetry/labelled_counter.rb
nanoc-4.8.11 lib/nanoc/telemetry/labelled_counter.rb
nanoc-4.8.10 lib/nanoc/telemetry/labelled_counter.rb
nanoc-4.8.9 lib/nanoc/telemetry/labelled_counter.rb
nanoc-4.8.8 lib/nanoc/telemetry/labelled_counter.rb
nanoc-4.8.7 lib/nanoc/telemetry/labelled_counter.rb
nanoc-4.8.6 lib/nanoc/telemetry/labelled_counter.rb
nanoc-4.8.5 lib/nanoc/telemetry/labelled_counter.rb
nanoc-4.8.4 lib/nanoc/telemetry/labelled_counter.rb
nanoc-4.8.3 lib/nanoc/telemetry/labelled_counter.rb
nanoc-4.8.2 lib/nanoc/telemetry/labelled_counter.rb
nanoc-4.8.1 lib/nanoc/telemetry/labelled_counter.rb
nanoc-4.8.0 lib/nanoc/telemetry/labelled_counter.rb
nanoc-4.7.14 lib/nanoc/telemetry/labelled_counter.rb
nanoc-4.7.13 lib/nanoc/telemetry/labelled_counter.rb
nanoc-4.7.12 lib/nanoc/telemetry/labelled_counter.rb
nanoc-4.7.11 lib/nanoc/telemetry/labelled_counter.rb
nanoc-4.7.10 lib/nanoc/telemetry/labelled_counter.rb