Sha256: 1368e84635a303cf46cd8f18531a932080e9cf7fca07e1fbd765c231e3aaba10

Contents?: true

Size: 425 Bytes

Versions: 6

Compression:

Stored size: 425 Bytes

Contents

module HashPersistent  
  module Counter  
    def self.included(base)
      base.extend ClassMethods
      base.module_eval do
        @next_key = 0
        @key_inc_lock = Mutex.new
      end
    end
    
    module ClassMethods
      def next_key
        the_key = nil
        @key_inc_lock.synchronize do
          the_key = @next_key.to_s
          @next_key += 1
        end
        the_key
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
kissifer-hash-persistent-0.1.1 lib/hash-persistent/counter.rb
kissifer-hash-persistent-0.2.0 lib/hash-persistent/counter.rb
kissifer-hash-persistent-0.2.1 lib/hash-persistent/counter.rb
kissifer-hash-persistent-0.2.2 lib/hash-persistent/counter.rb
kissifer-hash-persistent-0.3.1 lib/hash-persistent/counter.rb
kissifer-hash-persistent-0.3.2 lib/hash-persistent/counter.rb