Class: Foobara::Namespace::AmbiguousRegistry
- Inherits:
-
BaseRegistry
show all
- Defined in:
- foobara-0.0.110/projects/namespace/src/ambiguous_registry.rb
Instance Method Summary
collapse
#all_scoped, #apply_filter, #each_scoped, #registered?
Instance Method Details
#each_scoped_without_filter ⇒ Object
48
49
50
51
52
|
# File 'foobara-0.0.110/projects/namespace/src/ambiguous_registry.rb', line 48
def each_scoped_without_filter(&)
registry.each_value do |scoped_objects|
scoped_objects.each(&)
end
end
|
#lookup(path, filter = nil) ⇒ Object
39
40
41
42
43
44
45
46
|
# File 'foobara-0.0.110/projects/namespace/src/ambiguous_registry.rb', line 39
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
|
# File 'foobara-0.0.110/projects/namespace/src/ambiguous_registry.rb', line 8
def register(scoped)
short_name = scoped.scoped_short_name
registry[short_name] ||= []
registry[short_name] |= [scoped]
end
|
#registry ⇒ Object
4
5
6
|
# File 'foobara-0.0.110/projects/namespace/src/ambiguous_registry.rb', line 4
def registry
@registry ||= {}
end
|
#unregister(scoped) ⇒ Object
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
|
# File 'foobara-0.0.110/projects/namespace/src/ambiguous_registry.rb', line 14
def unregister(scoped)
short_name = scoped.scoped_short_name
entry = registry[short_name]
unless entry
raise NotRegisteredError, "Not registered: #{short_name.inspect}"
end
registered = lookup([short_name])
unless registered
raise NotRegisteredError, "Not registered: #{short_name.inspect}"
end
unless entry.delete(registered)
raise NotRegisteredError, "Not registered: #{short_name.inspect}"
end
end
|