Module: Unifig::Providers

Defined in:
lib/unifig/providers.rb,
lib/unifig/providers/local.rb

Defined Under Namespace

Modules: Local

Class Method Summary collapse

Class Method Details

.allObject



27
28
29
# File 'lib/unifig/providers.rb', line 27

def self.all
  @all ||= constants(false).map { |c| const_get(c, false) }.freeze
end

.list(providers = nil) ⇒ Object

Raises:



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
# File 'lib/unifig/providers.rb', line 7

def self.list(providers = nil)
  return all if providers.nil?

  providers.map do |provider|
    all
      .detect { |pp| pp.name == provider }
      .tap do |found|
        unless found
          msg = %("#{provider}" is not in the list of available providers)

          dym = DidYouMean::SpellChecker.new(dictionary: all.map(&:name))
          correction = dym.correct(provider).first
          msg += "\nDid you mean? #{correction}" if correction

          raise MissingProviderError, msg
        end
      end
  end
end