Sha256: 3daf87e9bc5b3370291c9ac2c7df2d209ccfb8b146a4d187a4bcc4d33b51451e

Contents?: true

Size: 779 Bytes

Versions: 15

Compression:

Stored size: 779 Bytes

Contents

# frozen_string_literal: true

require 'thread'

module WebMock
  module Util
    class HashCounter
      attr_accessor :hash

      def initialize
        self.hash = Hash.new(0)
        @order = {}
        @max = 0
        @lock = ::Mutex.new
      end

      def put(key, num=1)
        @lock.synchronize do
          hash[key] += num
          @order[key] = @max += 1
        end
      end

      def get(key)
        @lock.synchronize do
          hash[key]
        end
      end

      def select(&block)
        return unless block_given?

        @lock.synchronize do
          hash.select(&block)
        end
      end

      def each(&block)
        @order.to_a.sort_by { |a| a[1] }.each do |a|
          yield(a[0], hash[a[0]])
        end
      end
    end
  end
end

Version data entries

15 entries across 15 versions & 5 rubygems

Version Path
webmock-3.25.0 lib/webmock/util/hash_counter.rb
tailscale_middleware-0.0.3 vendor/cache/ruby/3.4.0/gems/webmock-3.24.0/lib/webmock/util/hash_counter.rb
minato_ruby_api_client-0.2.2 vendor/bundle/ruby/3.2.0/gems/webmock-3.23.1/lib/webmock/util/hash_counter.rb
webmock-3.24.0 lib/webmock/util/hash_counter.rb
blacklight-spotlight-3.6.0.beta8 vendor/bundle/ruby/3.2.0/gems/webmock-3.23.1/lib/webmock/util/hash_counter.rb
webmock-3.23.0 lib/webmock/util/hash_counter.rb
webmock-3.22.0 lib/webmock/util/hash_counter.rb
webmock-3.21.2 lib/webmock/util/hash_counter.rb
webmock-3.21.1 lib/webmock/util/hash_counter.rb
webmock-3.21.0 lib/webmock/util/hash_counter.rb
webmock-3.20.0 lib/webmock/util/hash_counter.rb
honeybadger-5.4.0 vendor/bundle/ruby/3.2.0/gems/webmock-3.19.1/lib/webmock/util/hash_counter.rb
honeybadger-5.3.0 vendor/bundle/ruby/3.2.0/gems/webmock-3.19.1/lib/webmock/util/hash_counter.rb
webmock-3.19.1 lib/webmock/util/hash_counter.rb
webmock-3.19.0 lib/webmock/util/hash_counter.rb