Sha256: b36be9c7b5b1784f14b93dfc59a7086b4dc251a5b725bb8b4dbbb0fdc8c9898a

Contents?: true

Size: 580 Bytes

Versions: 3

Compression:

Stored size: 580 Bytes

Contents

require 'singleton'

module NxtErrorRegistry
  class CodesHarness
    CodeAlreadyRegistered = Class.new(StandardError)
    include Singleton

    def generate_code
      generate_next_code
    rescue CodeAlreadyRegistered
      retry
    end

    def generate_next_code
      new_code = SecureRandom.uuid
      return new_code unless registered_codes.include?(new_code)

      raise CodeAlreadyRegistered, "#{new_code} already registered"
    end

    def registered_codes
      registry.codes
    end

    def registry
      NxtErrorRegistry::Registry.instance
    end
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nxt_error_registry-0.3.0 lib/nxt_error_registry/codes_harness.rb
nxt_error_registry-0.2.5 lib/nxt_error_registry/codes_harness.rb
nxt_error_registry-0.2.4 lib/nxt_error_registry/codes_harness.rb