Class: Formulary::FromUrlLoader Private

Inherits:
FormulaLoader show all
Defined in:
Library/Homebrew/formulary.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.

Loads formulae from URLs.

Instance Attribute Summary collapse

Attributes inherited from FormulaLoader

#alias_path, #name, #path

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) ⇒ FromUrlLoader

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


213
214
215
216
217
218
# File 'Library/Homebrew/formulary.rb', line 213

def initialize(url)
  @url = url
  uri = URI(url)
  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. You should avoid using this method if possible, as it may be removed or be changed in the future.


211
212
213
# File 'Library/Homebrew/formulary.rb', line 211

def url
  @url
end

Instance Method Details

#load_file(flags:) ⇒ 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.


220
221
222
223
224
225
226
227
228
229
230
231
232
233
234
235
236
237
238
239
# File 'Library/Homebrew/formulary.rb', line 220

def load_file(flags:)
  if url =~ %r{githubusercontent.com/[\w-]+/[\w-]+/[a-f0-9]{40}(/Formula)?/([\[email protected]]+).rb}
    formula_name = Regexp.last_match(2)
    odeprecated "Installation of #{formula_name} from a GitHub commit URL",
                "'brew extract #{formula_name}' to stable tap on GitHub"
  elsif url.match?(%r{^(https?|ftp)://})
    odeprecated "Non-checksummed download of #{name} formula file from an arbitrary URL",
                "'brew extract' or 'brew create' and 'brew tap-new' to create a "\
                "formula file in a tap on GitHub"
  end
  HOMEBREW_CACHE_FORMULA.mkpath
  FileUtils.rm_f(path)
  curl_download url, to: path
  super
rescue MethodDeprecatedError => e
  if url =~ %r{github.com/([\w-]+)/([\w-]+)/}
    e.issues_url = "https://github.com/#{Regexp.last_match(1)}/#{Regexp.last_match(2)}/issues/new"
  end
  raise
end