Class: URL

Inherits:
Object show all
Defined in:
url.rb

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(url, specs = {}) ⇒ 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:



31
32
33
34
35
36
37
# File 'url.rb', line 31

def initialize(url, specs = {})
  @url = T.let(url.freeze, String)
  @version = T.let(nil, T.nilable(Version))
  @specs = T.let(specs.dup, T::Hash[Symbol, T.untyped])
  @using = T.let(@specs.delete(:using), T.nilable(T.any(Symbol, T::Class[AbstractDownloadStrategy])))
  @specs.freeze
end

Instance Attribute Details

#specs ⇒ Hash{Symbol => T.untyped} (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.

Returns:



8
9
10
# File 'url.rb', line 8

def specs
  @specs
end

#using ⇒ Symbol, ... (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.

Returns:



11
12
13
# File 'url.rb', line 11

def using
  @using
end

Class Method Details

.automatic_mirror(url) ⇒ String?

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.

The mirror used by formula bumps for recognised upstream download URLs.

Parameters:

Returns:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'url.rb', line 15

def self.automatic_mirror(url)
  scheme, path = url.split("://", 2)
  return if path.nil? || %w[http https ftp].exclude?(scheme&.downcase)

  {
    "ftp.gnu.org/gnu/"                    => "ftpmirror.gnu.org/",
    "download.savannah.gnu.org/"          => "download-mirror.savannah.gnu.org/",
    "www.apache.org/dyn/closer.lua?path=" => "archive.apache.org/dist/",
    "mirrors.ocf.berkeley.edu/debian/"    => "mirrorservice.org/sites/ftp.debian.org/debian/",
  }.each do |upstream, mirror|
    return "#{scheme}://#{mirror}#{path.delete_prefix(upstream)}" if path.start_with?(upstream)
  end
  nil
end

Instance Method Details

#download_strategy ⇒ T::Class[AbstractDownloadStrategy]

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.

Returns:



45
46
47
48
# File 'url.rb', line 45

def download_strategy
  @download_strategy ||=
    T.let(DownloadStrategyDetector.detect(@url, @using), T.nilable(T::Class[AbstractDownloadStrategy]))
end

#version ⇒ Version

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.

Returns:



51
52
53
# File 'url.rb', line 51

def version
  @version ||= Version.detect(@url, tag: @specs[:tag])
end