Class: Foobara::Namespace::PrefixlessRegistry

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

Defined Under Namespace

Classes: RegisteringScopedWithPrefixError

Instance Method Summary collapse

Methods inherited from BaseRegistry

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

Instance Method Details

#each_scoped_without_filterObject



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

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

#lookup(path, filter = nil) ⇒ Object



34
35
36
37
38
# File 'foobara-0.0.110/projects/namespace/src/prefixless_registry.rb', line 34

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

#register(scoped) ⇒ Object



12
13
14
15
16
17
18
19
20
# File 'foobara-0.0.110/projects/namespace/src/prefixless_registry.rb', line 12

def register(scoped)
  key = to_key(scoped)

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

  registry[key] = scoped
end

#registryObject



8
9
10
# File 'foobara-0.0.110/projects/namespace/src/prefixless_registry.rb', line 8

def registry
  @registry ||= {}
end

#to_key(scoped) ⇒ Object



44
45
46
47
48
49
50
51
# File 'foobara-0.0.110/projects/namespace/src/prefixless_registry.rb', line 44

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

#unregister(scoped) ⇒ Object



22
23
24
25
26
27
28
29
30
31
32
# File 'foobara-0.0.110/projects/namespace/src/prefixless_registry.rb', line 22

def unregister(scoped)
  key = to_key(scoped)

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

  registry.delete(key)
end