Class: Formulary::FromNameLoader Private

Inherits:
FromTapLoader show all
Defined in:
formulary.rb

Overview

This class is part of a private API. This class may only be used in the Homebrew/brew repository. Third parties should avoid using this class if possible, as it may be removed or changed without warning.

Loads a formula from a name, as long as it exists only in a single tap.

Instance Attribute Summary

Attributes inherited from FromTapLoader

#path, #tap

Attributes inherited from FormulaLoader

#alias_path, #name, #path, #tap

Class Method Summary collapse

Methods inherited from FromTapLoader

#get_formula, #initialize, #load_file

Methods inherited from FormulaLoader

#get_formula, #initialize, #klass

Methods included from Context

current, current=, #debug?, #quiet?, #verbose?, #with_context

Constructor Details

This class inherits a constructor from Formulary::FromTapLoader

Class Method Details

.try_new(ref, from: T.unsafe(nil), warn: false) ⇒ T.attached_class?

This method is part of a private API. This method may only be used in the Homebrew/brew repository. Third parties should avoid using this method if possible, as it may be removed or changed without warning.

Parameters:

  • ref (String, Pathname, URI::Generic)
  • from (Symbol) (defaults to: T.unsafe(nil))
  • warn (Boolean) (defaults to: false)

Returns:

  • (T.attached_class, nil)


817
818
819
820
821
822
823
824
825
826
827
828
829
830
831
832
833
834
835
836
837
838
839
# File 'formulary.rb', line 817

def self.try_new(ref, from: T.unsafe(nil), warn: false)
  return unless ref.is_a?(String)
  return unless ref.match?(/\A#{HOMEBREW_TAP_FORMULA_NAME_REGEX}\Z/o)

  name = ref

  # If it exists in the default tap, never treat it as ambiguous with another tap.
  if (core_tap = CoreTap.instance).installed? &&
     (loader = super("#{core_tap}/#{name}", warn:))&.path&.exist?
    return loader
  end

  loaders = Tap.select { |tap| tap.installed? && !tap.core_tap? }
               .filter_map { |tap| super("#{tap}/#{name}", warn:) }
               .select { |tap| tap.path.exist? }

  case loaders.count
  when 1
    loaders.first
  when 2..Float::INFINITY
    raise TapFormulaAmbiguityError.new(name, loaders)
  end
end