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.



1316
1317
1318
1319
1320
1321
1322
1323
1324
1325
1326
1327
# File 'download_strategy.rb', line 1316

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.



1364
1365
1366
1367
1368
1369
1370
1371
1372
1373
1374
1375
1376
1377
1378
# File 'download_strategy.rb', line 1364

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



1329
1330
1331
1332
1333
1334
1335
1336
1337
1338
1339
1340
1341
1342
1343
1344
1345
1346
1347
1348
1349
1350
1351
1352
1353
1354
1355
1356
1357
1358
1359
1360
1361
1362
# File 'download_strategy.rb', line 1329

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/[^/]+/[^/]+$}
    GitDownloadStrategy
  when %r{^https?://www\.apache\.org/dyn/closer\.cgi},
       %r{^https?://www\.apache\.org/dyn/closer\.lua}
    CurlApacheMirrorDownloadStrategy
  when %r{^https?://(.+?\.)?googlecode\.com/svn},
       %r{^https?://svn\.},
       %r{^svn://},
       %r{^svn\+http://},
       %r{^http://svn\.apache\.org/repos/},
       %r{^https?://(.+?\.)?sourceforge\.net/svnroot/}
    SubversionDownloadStrategy
  when %r{^cvs://}
    CVSDownloadStrategy
  when %r{^hg://},
       %r{^https?://(.+?\.)?googlecode\.com/hg},
       %r{^https?://(.+?\.)?sourceforge\.net/hgweb/}
    MercurialDownloadStrategy
  when %r{^bzr://}
    BazaarDownloadStrategy
  when %r{^fossil://}
    FossilDownloadStrategy
  else
    CurlDownloadStrategy
  end
end