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



1454
1455
1456
1457
1458
1459
1460
1461
1462
1463
1464
1465
# File 'download_strategy.rb', line 1454

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



1503
1504
1505
1506
1507
1508
1509
1510
1511
1512
1513
1514
1515
1516
1517
1518
# File 'download_strategy.rb', line 1503

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



1467
1468
1469
1470
1471
1472
1473
1474
1475
1476
1477
1478
1479
1480
1481
1482
1483
1484
1485
1486
1487
1488
1489
1490
1491
1492
1493
1494
1495
1496
1497
1498
1499
1500
1501
# File 'download_strategy.rb', line 1467

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{^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