Class: Foobara::Namespace::BaseRegistry

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

Defined Under Namespace

Classes: NotRegisteredError, WouldMakeRegistryAmbiguousError

Instance Method Summary collapse

Instance Method Details

#all_scoped(filter: nil) ⇒ Object



39
40
41
42
43
44
45
# File 'foobara-0.0.110/projects/namespace/src/base_registry.rb', line 39

def all_scoped(filter: nil)
  all = []
  each_scoped(filter:) do |scoped|
    all << scoped
  end
  all
end

#apply_filter(object, filter) ⇒ Object



53
54
55
56
57
58
59
60
61
62
63
# File 'foobara-0.0.110/projects/namespace/src/base_registry.rb', line 53

def apply_filter(object, filter)
  if filter
    if object.is_a?(::Array)
      object.select { |o| o.instance_eval(&filter) }
    elsif object&.instance_eval(&filter)
      object
    end
  else
    object
  end
end

#each_scoped(filter: nil, &block) ⇒ Object

TODO: should return an enumerator



32
33
34
35
36
37
# File 'foobara-0.0.110/projects/namespace/src/base_registry.rb', line 32

def each_scoped(filter: nil, &block)
  each_scoped_without_filter do |scoped|
    scoped = apply_filter(scoped, filter) if filter
    block.call(scoped) if scoped
  end
end

#each_scoped_without_filterObject



47
48
49
50
51
# File 'foobara-0.0.110/projects/namespace/src/base_registry.rb', line 47

def each_scoped_without_filter(&)
  # :nocov:
  raise "Subclass responsibility"
  # :nocov:
end

#lookup(_path, filter: nil) ⇒ Object



25
26
27
28
29
# File 'foobara-0.0.110/projects/namespace/src/base_registry.rb', line 25

def lookup(_path, filter: nil)
  # :nocov:
  raise "Subclass responsibility"
  # :nocov:
end

#register(_scoped) ⇒ Object



9
10
11
12
13
# File 'foobara-0.0.110/projects/namespace/src/base_registry.rb', line 9

def register(_scoped)
  # :nocov:
  raise "Subclass responsibility"
  # :nocov:
end

#registered?(path) ⇒ Boolean

Returns:

  • (Boolean)


15
16
17
# File 'foobara-0.0.110/projects/namespace/src/base_registry.rb', line 15

def registered?(path)
  !lookup(path).nil?
end

#unregister(_scoped) ⇒ Object



19
20
21
22
23
# File 'foobara-0.0.110/projects/namespace/src/base_registry.rb', line 19

def unregister(_scoped)
  # :nocov:
  raise "Subclass responsibility"
  # :nocov:
end