Class: Foobara::Namespace::AmbiguousRegistry

Inherits:
BaseRegistry show all
Defined in:
foobara-0.2.6/projects/namespace/src/ambiguous_registry.rb

Instance Method Summary collapse

Methods inherited from BaseRegistry

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

Instance Method Details

#each_scoped_without_filterObject



46
47
48
49
50
# File 'projects/namespace/src/ambiguous_registry.rb', line 46

def each_scoped_without_filter(&)
  registry.each_value do |scoped_objects|
    scoped_objects.each(&)
  end
end

#lookup(path, filter = nil) ⇒ Object



37
38
39
40
41
42
43
44
# File 'projects/namespace/src/ambiguous_registry.rb', line 37

def lookup(path, filter = nil)
  *prefix, short_name = path
  matches = apply_filter(registry[short_name], filter)

  if matches && !matches.empty?
    _best_match(prefix, matches, path)
  end
end

#register(scoped) ⇒ Object



8
9
10
11
12
13
14
15
16
17
18
# File 'projects/namespace/src/ambiguous_registry.rb', line 8

def register(scoped)
  short_name = scoped.scoped_short_name
  registry[short_name] ||= []
  # This kind of error should only happen in test suites that need to unregister/reregister things
  # with different object_ids but the same scoped full name. So will check it in commented out.
  # if registry[short_name].map(&:scoped_full_name).include?(scoped.scoped_full_name)
  #   raise "Already registered: #{scoped.scoped_full_name}"
  # end

  registry[short_name] |= [scoped]
end

#registryObject



4
5
6
# File 'projects/namespace/src/ambiguous_registry.rb', line 4

def registry
  @registry ||= {}
end

#unregister(scoped) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'projects/namespace/src/ambiguous_registry.rb', line 20

def unregister(scoped)
  short_name = scoped.scoped_short_name
  entry = registry[short_name]

  unless entry
    # :nocov:
    raise NotRegisteredError, "Not registered: #{short_name.inspect}"
    # :nocov:
  end

  unless entry.delete(scoped)
    # :nocov:
    raise NotRegisteredError, "Not registered: #{short_name.inspect}"
    # :nocov:
  end
end