Class: DownloadStrategyDetector

Inherits:
Object
  • Object
show all
Defined in:
lib/lace/download_strategy.rb

Class Method Summary collapse

Class Method Details

.detect(uri, strategy = nil) ⇒ Object



180
181
182
183
184
185
186
187
188
189
# File 'lib/lace/download_strategy.rb', line 180

def self.detect(uri, strategy=nil)
  if strategy.nil?
    detect_from_uri(uri)
  elsif Symbol === strategy
    detect_from_symbol(strategy)
  else
    raise TypeError,
      "Unknown download strategy specification #{strategy.inspect}"
  end
end

.detect_from_symbol(symbol) ⇒ Object



211
212
213
214
215
216
217
218
# File 'lib/lace/download_strategy.rb', line 211

def self.detect_from_symbol(symbol)
  case symbol
  when :git then GitDownloadStrategy
  when :local_file then LocalFileStrategy
  else
    raise "Unknown download strategy #{strategy} was requested."
  end
end

.detect_from_uri(uri) ⇒ Object



191
192
193
194
195
196
197
198
199
200
201
202
203
204
205
206
207
208
209
# File 'lib/lace/download_strategy.rb', line 191

def self.detect_from_uri(uri)
  is_git_dir = File.directory?(uri+"/.git")
  has_single_slash = uri.scan("/").count == 1
  if File.directory?(uri) && !is_git_dir
    return LocalFileStrategy
  elsif is_git_dir
    return GitDownloadStrategy
  elsif has_single_slash
    return AbbrevGitDownloadStrategy
  end

  case uri
    when %r[^git://] then GitDownloadStrategy
    when %r[^https?://.+\.git$] then GitDownloadStrategy
    # else CurlDownloadStrategy
  else
    raise "Cannot determine download startegy from #{uri}"
  end
end