Class: DownloadStrategyDetector

Inherits:
Object
  • Object
show all
Defined in:
brew/Library/Homebrew/download_strategy.rb

Class Method Summary collapse

Class Method Details

.detect(url, using = nil) ⇒ Object



1062
1063
1064
1065
1066
1067
1068
1069
1070
1071
1072
1073
1074
1075
# File 'brew/Library/Homebrew/download_strategy.rb', line 1062

def self.detect(url, using = nil)
  strategy = 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 #{strategy.inspect}"
  end

  strategy
end

.detect_from_symbol(symbol) ⇒ Object



1111
1112
1113
1114
1115
1116
1117
1118
1119
1120
1121
1122
1123
1124
1125
# File 'brew/Library/Homebrew/download_strategy.rb', line 1111

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 "Unknown download strategy #{symbol} was requested."
  end
end

.detect_from_url(url) ⇒ Object



1077
1078
1079
1080
1081
1082
1083
1084
1085
1086
1087
1088
1089
1090
1091
1092
1093
1094
1095
1096
1097
1098
1099
1100
1101
1102
1103
1104
1105
1106
1107
1108
1109
# File 'brew/Library/Homebrew/download_strategy.rb', line 1077

def self.detect_from_url(url)
  case url
  when %r{^https?://github\.com/[^/]+/[^/]+\.git$}
    GitHubGitDownloadStrategy
  when %r{^https?://.+\.git$},
       %r{^git://}
    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{^https?://(.+?\.)?sourceforge\.net/svnroot/}
    SubversionDownloadStrategy
  when %r{^cvs://}
    CVSDownloadStrategy
  when %r{^hg://},
       %r{^https?://(.+?\.)?googlecode\.com/hg}
    MercurialDownloadStrategy
  when %r{^bzr://}
    BazaarDownloadStrategy
  when %r{^fossil://}
    FossilDownloadStrategy
  when %r{^svn\+http://},
       %r{^http://svn\.apache\.org/repos/}
    SubversionDownloadStrategy
  when %r{^https?://(.+?\.)?sourceforge\.net/hgweb/}
    MercurialDownloadStrategy
  else
    CurlDownloadStrategy
  end
end