Class: DownloadStrategyDetector

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

Class Method Summary collapse

Class Method Details

.detect(url, strategy = nil) ⇒ Object



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

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

.detect_from_symbol(symbol) ⇒ Object



1152
1153
1154
1155
1156
1157
1158
1159
1160
1161
1162
1163
1164
1165
1166
1167
# File 'Library/Homebrew/download_strategy.rb', line 1152

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 :ssl3    then CurlSSL3DownloadStrategy
  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



1125
1126
1127
1128
1129
1130
1131
1132
1133
1134
1135
1136
1137
1138
1139
1140
1141
1142
1143
1144
1145
1146
1147
1148
1149
1150
# File 'Library/Homebrew/download_strategy.rb', line 1125

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