Class: Implements::Implementation::Registry Private

Inherits:
Object
  • Object
show all
Defined in:
lib/implements/implementation/registry.rb

Overview

This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.

A registry of implementations, held by an interface.

Defined Under Namespace

Classes: Element, Finder

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(interface) ⇒ Registry

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns a new instance of Registry.

Parameters:



12
13
14
15
# File 'lib/implements/implementation/registry.rb', line 12

def initialize(interface)
  @interface = interface
  @elements = []
end

Instance Attribute Details

#interfaceObject (readonly)

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.



16
17
18
# File 'lib/implements/implementation/registry.rb', line 16

def interface
  @interface
end

Instance Method Details

#elements(selectors) ⇒ Enumerator<Element>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns an enumerator of elements matching the given selectors, in the order specified; this is used by Implements::Implementation::Registry::Finder#find.

Parameters:

  • selectors (#to_s, Array<#to_s>)
    • one or more selectors

Returns:



22
23
24
25
26
27
28
29
30
# File 'lib/implements/implementation/registry.rb', line 22

def elements(selectors)
  Enumerator.new do |yielder|
    yielded = Set.new
    Array(selectors).product(@elements) do |selector, element|
      next unless element.match?(selector)
      yielder << element if yielded.add?(element)
    end
  end
end

#list_namesArray<String>

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Returns:

  • (Array<String>)


34
35
36
# File 'lib/implements/implementation/registry.rb', line 34

def list_names
  @elements.map(&:name).compact
end

#register(implementation, options, check) ⇒ Object

This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.

Parameters:

  • implementation (Implementation)
  • options (Hash{Symbol=>Object})

    (see: Element#initialize)

  • check (#call, nil)


42
43
44
# File 'lib/implements/implementation/registry.rb', line 42

def register(implementation, options, check)
  @elements.unshift Element.new(self, implementation, options, check)
end