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.



1444
1445
1446
1447
1448
1449
1450
1451
1452
1453
1454
1455
# File 'download_strategy.rb', line 1444

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.



1493
1494
1495
1496
1497
1498
1499
1500
1501
1502
1503
1504
1505
1506
1507
1508
# File 'download_strategy.rb', line 1493

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.



1457
1458
1459
1460
1461
1462
1463
1464
1465
1466
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
# File 'download_strategy.rb', line 1457

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