Sha256: 293913d5417884af1d83de1bbb90171e74552941e908a37d1b697cd05a6a6883

Contents?: true

Size: 1.08 KB

Versions: 3

Compression:

Stored size: 1.08 KB

Contents

require 'active_support/core_ext'
require 'nxt_registry/version'
require 'nxt_registry/blank'
require 'nxt_registry/attribute'
require 'nxt_registry/errors'
require 'nxt_registry/registry_builder'
require 'nxt_registry/registry'
require 'nxt_registry/recursive_registry'

module NxtRegistry
  def registry(name, **options, &config)
    build_registry(Registry, name, **options, &config)
  end

  def recursive_registry(name, **options, &config)
    build_registry(RecursiveRegistry, name, **options, &config)
  end

  private

  def build_registry(registry_class, name, **options, &config)
    if registries.key?(name)
      registry = registries.fetch(name)
      if registry.configured
        registry
      else
        raise_unconfigured_registry_accessed(name)
      end
    else
      registry = registry_class.new(name, **options, &config)
      registries[name] ||= registry
      registry
    end
  end

  def raise_unconfigured_registry_accessed(name)
    raise ArgumentError, "The registry #{name} must be configured before accessed!"
  end

  def registries
    @registries ||= {}
  end
end

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
nxt_registry-0.3.3 lib/nxt_registry.rb
nxt_registry-0.3.2 lib/nxt_registry.rb
nxt_registry-0.3.1 lib/nxt_registry.rb