Sha256: 4e2348df4f07aaeb0975f3262efb328eeee30fe3d4909ca8d25f41fd29f9f0a5

Contents?: true

Size: 638 Bytes

Versions: 154

Compression:

Stored size: 638 Bytes

Contents

require 'thread'

module WebMock
  module Util
    class Util::HashCounter
      attr_accessor :hash
      def initialize
        self.hash = {}
        @order = {}
        @max = 0
        @lock = ::Mutex.new
      end
      def put key, num=1
        @lock.synchronize do
          hash[key] = (hash[key] || 0) + num
          @order[key] = @max = @max + 1
        end
      end
      def get key
        @lock.synchronize do
          hash[key] || 0
        end
      end

      def each(&block)
        @order.to_a.sort {|a, b| a[1] <=> b[1]}.each do |a|
          block.call(a[0], hash[a[0]])
        end
      end
    end
  end
end

Version data entries

154 entries across 143 versions & 12 rubygems

Version Path
docspring-3.0.0 vendor/bundle/ruby/3.3.0/gems/webmock-1.24.6/lib/webmock/util/hash_counter.rb
cloudsmith-api-2.0.16 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/lib/webmock/util/hash_counter.rb
cloudsmith-api-2.0.15 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/lib/webmock/util/hash_counter.rb
cloudsmith-api-2.0.14 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/lib/webmock/util/hash_counter.rb
cloudsmith-api-2.0.13 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/lib/webmock/util/hash_counter.rb
cloudsmith-api-2.0.12 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/lib/webmock/util/hash_counter.rb
cloudsmith-api-2.0.11 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/lib/webmock/util/hash_counter.rb
cloudsmith-api-2.0.10 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/lib/webmock/util/hash_counter.rb
cloudsmith-api-2.0.9 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/lib/webmock/util/hash_counter.rb
cloudsmith-api-2.0.8 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/lib/webmock/util/hash_counter.rb
cloudsmith-api-2.0.7 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/lib/webmock/util/hash_counter.rb
cloudsmith-api-2.0.6 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/lib/webmock/util/hash_counter.rb
cloudsmith-api-2.0.5 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/lib/webmock/util/hash_counter.rb
cloudsmith-api-2.0.4 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/lib/webmock/util/hash_counter.rb
cloudsmith-api-2.0.3 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/lib/webmock/util/hash_counter.rb
cloudsmith-api-2.0.2 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/lib/webmock/util/hash_counter.rb
cloudsmith-api-2.0.1 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/lib/webmock/util/hash_counter.rb
cloudsmith-api-2.0.0 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/lib/webmock/util/hash_counter.rb
cloudsmith-api-1.142.3 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/lib/webmock/util/hash_counter.rb
cloudsmith-api-1.120.3 vendor/bundle/ruby/2.6.0/gems/webmock-1.24.6/lib/webmock/util/hash_counter.rb