Class: DownloadStrategyDetector Private

Inherits:
Object
  • Object
show all
Defined in:
download_strategy.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.

Helper class for detecting a download strategy from a URL.

Class Method Summary collapse

Class Method Details

.detect(url, using = nil) ⇒ 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.

Parameters:

Returns:



1619
1620
1621
1622
1623
1624
1625
1626
1627
1628
1629
1630
# File 'download_strategy.rb', line 1619

def self.detect(url, using = nil)
  if using.nil?
    detect_from_url(url)
  elsif using.is_a?(Class) && using < AbstractDownloadStrategy
    using
  elsif using.is_a?(Symbol)
    detect_from_symbol(using)
  else
    raise TypeError,
          "Unknown download strategy specification: #{using.inspect}"
  end
end

.detect_from_symbol(symbol) ⇒ 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.

Parameters:

Returns:



1671
1672
1673
1674
1675
1676
1677
1678
1679
1680
1681
1682
1683
1684
1685
1686
# File 'download_strategy.rb', line 1671

def self.detect_from_symbol(symbol)
  case symbol
  when :hg                     then MercurialDownloadStrategy
  when :nounzip                then NoUnzipCurlDownloadStrategy
  when :git                    then GitDownloadStrategy
  when :bzr                    then BazaarDownloadStrategy
  when :svn                    then SubversionDownloadStrategy
  when :curl                   then CurlDownloadStrategy
  when :homebrew_curl          then HomebrewCurlDownloadStrategy
  when :cvs                    then CVSDownloadStrategy
  when :post                   then CurlPostDownloadStrategy
  when :fossil                 then FossilDownloadStrategy
  else
    raise TypeError, "Unknown download strategy #{symbol} was requested."
  end
end

.detect_from_url(url) ⇒ 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.

Parameters:

Returns:



1633
1634
1635
1636
1637
1638
1639
1640
1641
1642
1643
1644
1645
1646
1647
1648
1649
1650
1651
1652
1653
1654
1655
1656
1657
1658
1659
1660
1661
1662
1663
1664
1665
1666
1667
1668
# File 'download_strategy.rb', line 1633

def self.detect_from_url(url)
  case url
  when GitHubPackages::URL_REGEX
    CurlGitHubPackagesDownloadStrategy
  when %r{^https?://github\.com/[^/]+/[^/]+\.git$}
    GitHubGitDownloadStrategy
  when %r{^https?://.+\.git$},
       %r{^git://},
       %r{^https?://git\.sr\.ht/[^/]+/[^/]+$},
       %r{^https?://tangled\.sh/[^/]+/[^/]+$},
       %r{^ssh://git}
    GitDownloadStrategy
  when %r{^https?://www\.apache\.org/dyn/closer\.cgi},
       %r{^https?://www\.apache\.org/dyn/closer\.lua}
    CurlApacheMirrorDownloadStrategy
  when %r{^https?://([A-Za-z0-9\-.]+\.)?googlecode\.com/svn},
       %r{^https?://svn\.},
       %r{^svn://},
       %r{^svn\+http://},
       %r{^http://svn\.apache\.org/repos/},
       %r{^https?://([A-Za-z0-9\-.]+\.)?sourceforge\.net/svnroot/}
    SubversionDownloadStrategy
  when %r{^cvs://}
    CVSDownloadStrategy
  when %r{^hg://},
       %r{^https?://([A-Za-z0-9\-.]+\.)?googlecode\.com/hg},
       %r{^https?://([A-Za-z0-9\-.]+\.)?sourceforge\.net/hgweb/}
    MercurialDownloadStrategy
  when %r{^bzr://}
    BazaarDownloadStrategy
  when %r{^fossil://}
    FossilDownloadStrategy
  else
    CurlDownloadStrategy
  end
end