Class: DownloadStrategyDetector

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

Class Method Summary collapse

Class Method Details

.detect(uri) ⇒ Object



171
172
173
# File 'lib/lace/download_strategy.rb', line 171

def self.detect(uri)
  detect_from_uri(uri)
end

.detect_from_uri(uri) ⇒ Object



175
176
177
178
179
180
181
182
183
184
185
186
187
188
189
190
191
192
193
194
195
# File 'lib/lace/download_strategy.rb', line 175

def self.detect_from_uri(uri)
  is_git_dir = File.directory?("#{uri}/.git")
  has_single_slash = uri.scan('/').count == 1
  via_ssh = uri.start_with?('git@')

  if File.directory?(uri) && !is_git_dir && !via_ssh
    return LocalFileStrategy
  elsif is_git_dir
    return GitDownloadStrategy
  elsif has_single_slash && !via_ssh
    return GitHubDownloadStrategy
  end

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