Class: Foobara::Namespace::UnambiguousRegistry

Inherits:
BaseRegistry
  • Object
show all
Defined in:
foobara-0.0.110/projects/namespace/src/unambiguous_registry.rb

Instance Method Summary collapse

Methods inherited from BaseRegistry

#all_scoped, #apply_filter, #each_scoped, #registered?

Instance Method Details

#each_scoped_without_filterObject



43
44
45
46
# File 'foobara-0.0.110/projects/namespace/src/unambiguous_registry.rb', line 43

def each_scoped_without_filter(&)
  # records can be unregistered in the block so dup first
  all.dup.each(&)
end

#lookup(path, filter = nil) ⇒ Object



39
40
41
# File 'foobara-0.0.110/projects/namespace/src/unambiguous_registry.rb', line 39

def lookup(path, filter = nil)
  apply_filter(registry[path], filter)
end

#register(scoped) ⇒ Object



10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'foobara-0.0.110/projects/namespace/src/unambiguous_registry.rb', line 10

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

#registryObject



6
7
8
# File 'foobara-0.0.110/projects/namespace/src/unambiguous_registry.rb', line 6

def registry
  @registry ||= {}
end

#unregister(scoped) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
# File 'foobara-0.0.110/projects/namespace/src/unambiguous_registry.rb', line 27

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