Sha256: 6afb745ea46c176fb8743632eef513f0adc98af3369d0c570c6b16f8276ddaa8
Contents?: true
Size: 1.43 KB
Versions: 26
Compression:
Stored size: 1.43 KB
Contents
require_relative "base_registry" module Foobara class Namespace class UnambiguousRegistry < BaseRegistry def registry @registry ||= {} end def register(scoped) new_entries = {} to_keys(scoped).each do |key| if registry.key?(key) raise WouldMakeRegistryAmbiguousError, "Ambiguous match for #{key.inspect}. Matches the following: #{registry[key].inspect}" end new_entries[key] = scoped end all << scoped registry.merge!(new_entries) end def unregister(scoped) all.delete(scoped) to_keys(scoped).each do |key| unless registry.key?(key) raise NotRegisteredError, "Not registered: #{key.inspect}" end registry.delete(key) end end def lookup(path, filter = nil) apply_filter(registry[path], filter) end def each_scoped_without_filter(&) # records can be unregistered in the block so dup first all.dup.each(&) end private # TODO: why don't we do this in UnambiguousRegistry?? def to_keys(scoped) short_name = scoped.scoped_short_name prefixes = scoped.scoped_prefix ? Util.power_set(scoped.scoped_prefix) : [[]] prefixes.map do |prefix| [*prefix, *short_name] end end def all @all ||= [] end end end end
Version data entries
26 entries across 26 versions & 1 rubygems