Class | Limelight::Util::Downloader |
In: |
lib/limelight/util/downloader.rb
|
Parent: | Object |
# File lib/limelight/util/downloader.rb, line 16 16: def self.download(resource) 17: new.download(resource) 18: end
# File lib/limelight/util/downloader.rb, line 20 20: def initialize 21: Data.establish_data_dirs 22: end
# File lib/limelight/util/downloader.rb, line 24 24: def download(resource) 25: uri = URI.parse(resource) 26: case uri.scheme 27: when nil, "file" 28: download_file(uri) 29: when 'http', 'https' 30: download_http(uri) 31: else 32: raise LimelightException.new("Download failed. Unhandled URI scheme: #{uri.scheme}") 33: end 34: end
# File lib/limelight/util/downloader.rb, line 36 36: def download_file(uri) 37: raise LimelightException.new("Download failed. Not found: #{uri.path}") if !File.exists?(uri.path) 38: filename = File.basename(uri.path) 39: destination = find_unused_downloads_filename(filename) 40: File.copy(uri.path, destination) 41: return destination 42: end