Class: Formulary::FromURILoader Private

Inherits:
FormulaLoader 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 formula from a URI.

Instance Attribute Summary collapse

Attributes inherited from FormulaLoader

#alias_path, #name, #path, #tap

Class Method Summary collapse

Instance Method Summary collapse

Methods inherited from FormulaLoader

#get_formula, #klass

Methods included from Context

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

Constructor Details

#initialize(url, from: nil) ⇒ void

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:

  • url (URI::Generic, String)
  • from (Symbol, nil) (defaults to: nil)

Raises:

  • (ArgumentError)


725
726
727
728
729
730
731
732
733
# File 'formulary.rb', line 725

def initialize(url, from: nil)
  @url = url
  @from = from
  uri_path = URI(url).path
  raise ArgumentError, "URL has no path component" unless uri_path

  formula = File.basename(uri_path, ".rb")
  super formula, HOMEBREW_CACHE_FORMULA/File.basename(uri_path)
end

Instance Attribute Details

#urlObject (readonly)

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.



722
723
724
# File 'formulary.rb', line 722

def url
  @url
end

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)


703
704
705
706
707
708
709
710
711
712
713
714
715
716
717
718
719
720
# File 'formulary.rb', line 703

def self.try_new(ref, from: T.unsafe(nil), warn: false)
  return if Homebrew::EnvConfig.forbid_packages_from_paths?

  # Cache compiled regex
  @uri_regex ||= begin
    uri_regex = ::URI::DEFAULT_PARSER.make_regexp
    Regexp.new("\\A#{uri_regex.source}\\Z", uri_regex.options)
  end

  uri = ref.to_s
  return unless uri.match?(@uri_regex)

  uri = URI(uri)
  return unless uri.path
  return unless uri.scheme.present?

  new(uri, from:)
end

Instance Method Details

#load_file(flags:, ignore_errors:) ⇒ Object

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.



735
736
737
738
739
740
741
742
743
744
745
746
747
748
749
750
751
752
# File 'formulary.rb', line 735

def load_file(flags:, ignore_errors:)
  url_scheme = URI(url).scheme
  if ALLOWED_URL_SCHEMES.exclude?(url_scheme)
    raise UnsupportedInstallationMethod,
          "Non-checksummed download of #{name} formula file from an arbitrary URL is unsupported! " \
          "`brew extract` or `brew create` and `brew tap-new` to create a formula file in a tap " \
          "on GitHub instead."
  end
  HOMEBREW_CACHE_FORMULA.mkpath
  FileUtils.rm_f(path)
  Utils::Curl.curl_download url, to: path
  super
rescue MethodDeprecatedError => e
  if (match_data = url.match(%r{github.com/(?<user>[\w-]+)/(?<repo>[\w-]+)/}).presence)
    e.issues_url = "https://github.com/#{match_data[:user]}/#{match_data[:repo]}/issues/new"
  end
  raise
end