Class: Implements::Implementation::Registry::Finder Private

Inherits:
Object
  • Object
show all
Defined in:
lib/implements/implementation/registry/finder.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 Finder, plumbed to a Registry.

Instance Method Summary collapse

Constructor Details

#initialize(registry, selectors) ⇒ Finder

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 Finder.

Parameters:



10
11
12
13
# File 'lib/implements/implementation/registry/finder.rb', line 10

def initialize(registry, selectors)
  @registry = registry
  @selectors = selectors
end

Instance Method Details

#find(*args) ⇒ 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.

Find a suitable implementation of the given interface, given the args that would be passed to its #initialize and our selectors



27
28
29
30
31
32
33
34
35
# File 'lib/implements/implementation/registry/finder.rb', line 27

def find(*args)
  @registry.elements(@selectors).each do |config|
    next unless config.check?(*args)
    return config.implementation
  end

  fail(Implementation::NotFound,
       "no compatible implementation for #{inspect}")
end

#inspectObject

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.



38
39
40
# File 'lib/implements/implementation/registry/finder.rb', line 38

def inspect
  "<#{@registry.interface}::implementation(#{@selectors.join(', ')})>"
end

#new(*args, &block) ⇒ 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.

Returns an instance of the @registry.interface that supports the given arguments.



18
19
20
21
# File 'lib/implements/implementation/registry/finder.rb', line 18

def new(*args, &block)
  implementation = find(*args)
  implementation.new(*args, &block)
end