Sha256: 0649cf8e4df80c4e16b38b49aa94e7c13c3ddee831a6f3efbd87ff81e3bc2a18

Contents?: true

Size: 634 Bytes

Versions: 6

Compression:

Stored size: 634 Bytes

Contents

# frozen_string_literal: true

require 'singleton'

module ROM
  module Factory
    # @api private
    class Sequences
      include Singleton

      # @api private
      attr_reader :registry

      # @api private
      def self.[](relation)
        key = :"#{relation.gateway}-#{relation.name.dataset}"
        -> { instance.next(key) }
      end

      # @api private
      def initialize
        reset
      end

      # @api private
      def next(key)
        registry[key] += 1
      end

      # @api private
      def reset
        @registry = Concurrent::Map.new { |h, k| h[k] = 0 }
        self
      end
    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
rom-factory-0.10.2 lib/rom/factory/sequences.rb
rom-factory-0.10.1 lib/rom/factory/sequences.rb
rom-factory-0.10.0 lib/rom/factory/sequences.rb
rom-factory-0.9.1 lib/rom/factory/sequences.rb
rom-factory-0.9.0 lib/rom/factory/sequences.rb
rom-factory-0.8.0 lib/rom/factory/sequences.rb