Sha256: 7da9a37c94af6f33d7c5e6f190d16e38ac45166cb688ea00881ac5ca015848cd

Contents?: true

Size: 664 Bytes

Versions: 2

Compression:

Stored size: 664 Bytes

Contents

# frozen_string_literal: true

require "concurrent/map"
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.compute(key) { |v| (v || 0).succ }
      end

      # @api private
      def reset
        @registry = Concurrent::Map.new
        self
      end
    end
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
rom-factory-0.13.0 lib/rom/factory/sequences.rb
rom-factory-0.12.0 lib/rom/factory/sequences.rb