Sha256: 8294c1af0735583e8de33c6bc1531493f5d6ff0503495230944e8162c2cd8ca9

Contents?: true

Size: 762 Bytes

Versions: 61

Compression:

Stored size: 762 Bytes

Contents

require 'thread'

module WebMock
  module Util
    class 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 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

61 entries across 61 versions & 5 rubygems

Version Path
logstash-output-scalyr-0.1.19.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/util/hash_counter.rb
logstash-output-scalyr-0.1.18.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/util/hash_counter.rb
logstash-output-scalyr-0.1.17.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/util/hash_counter.rb
logstash-output-scalyr-0.1.16.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/util/hash_counter.rb
logstash-output-scalyr-0.1.15.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/util/hash_counter.rb
logstash-output-scalyr-0.1.14.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/util/hash_counter.rb
logstash-output-scalyr-0.1.13 vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/util/hash_counter.rb
logstash-output-scalyr-0.1.12 vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/util/hash_counter.rb
logstash-output-scalyr-0.1.11.beta vendor/bundle/jruby/2.5.0/gems/webmock-3.13.0/lib/webmock/util/hash_counter.rb
webmock-3.13.0 lib/webmock/util/hash_counter.rb
webmock-3.12.2 lib/webmock/util/hash_counter.rb
webmock-3.12.1 lib/webmock/util/hash_counter.rb
webmock-3.12.0 lib/webmock/util/hash_counter.rb
webmock-3.11.3 lib/webmock/util/hash_counter.rb
logstash-output-newrelic-1.2.0 vendor/bundle/jruby/2.5.0/gems/webmock-3.11.2/lib/webmock/util/hash_counter.rb
webmock-3.11.2 lib/webmock/util/hash_counter.rb
webmock-3.11.1 lib/webmock/util/hash_counter.rb
webmock-3.11.0 lib/webmock/util/hash_counter.rb
webmock-3.10.0 lib/webmock/util/hash_counter.rb
webmock-3.9.5 lib/webmock/util/hash_counter.rb