Sha256: b44fec6128b8c46f99b14b8531098be959c9b1e4e063f2b2460e458f3014b332

Contents?: true

Size: 1.16 KB

Versions: 26

Compression:

Stored size: 1.16 KB

Contents

require_relative "base_registry"

module Foobara
  class Namespace
    class PrefixlessRegistry < BaseRegistry
      class RegisteringScopedWithPrefixError < StandardError; end

      def registry
        @registry ||= {}
      end

      def register(scoped)
        key = to_key(scoped)

        if registry.key?(key)
          raise WouldMakeRegistryAmbiguousError, "#{key} is already registered"
        end

        registry[key] = scoped
      end

      def unregister(scoped)
        key = to_key(scoped)

        unless registry.key?(key)
          # :nocov:
          raise NotRegisteredError, "#{key} is not registered"
          # :nocov:
        end

        registry.delete(key)
      end

      def lookup(path, filter = nil)
        if path.size == 1
          apply_filter(registry[path.first], filter)
        end
      end

      def each_scoped_without_filter(&)
        registry.each_value(&)
      end

      def to_key(scoped)
        if scoped.scoped_prefix
          raise RegisteringScopedWithPrefixError,
                "Cannot register scoped with a prefix: #{scoped.scoped_name.inspect}"
        end

        scoped.scoped_short_name
      end
    end
  end
end

Version data entries

26 entries across 26 versions & 1 rubygems

Version Path
foobara-0.0.26 projects/namespace/src/prefixless_registry.rb
foobara-0.0.25 projects/namespace/src/prefixless_registry.rb
foobara-0.0.24 projects/namespace/src/prefixless_registry.rb
foobara-0.0.23 projects/namespace/src/prefixless_registry.rb
foobara-0.0.22 projects/namespace/src/prefixless_registry.rb
foobara-0.0.21 projects/namespace/src/prefixless_registry.rb
foobara-0.0.20 projects/namespace/src/prefixless_registry.rb
foobara-0.0.19 projects/namespace/src/prefixless_registry.rb
foobara-0.0.18 projects/namespace/src/prefixless_registry.rb
foobara-0.0.17 projects/namespace/src/prefixless_registry.rb
foobara-0.0.16 projects/namespace/src/prefixless_registry.rb
foobara-0.0.15 projects/namespace/src/prefixless_registry.rb
foobara-0.0.14 projects/namespace/src/prefixless_registry.rb
foobara-0.0.13 projects/namespace/src/prefixless_registry.rb
foobara-0.0.12 projects/namespace/src/prefixless_registry.rb
foobara-0.0.11 projects/namespace/src/prefixless_registry.rb
foobara-0.0.10 projects/namespace/src/prefixless_registry.rb
foobara-0.0.9 projects/namespace/src/prefixless_registry.rb
foobara-0.0.8 projects/namespace/src/prefixless_registry.rb
foobara-0.0.7 projects/namespace/src/prefixless_registry.rb