Class: SudachiInstaller::Downloader
- Inherits:
-
Object
- Object
- SudachiInstaller::Downloader
- Extended by:
- Dry::Configurable
- Defined in:
- lib/sudachi-installer/downloader.rb
Overview
download and expand archive if it is zip archive
Instance Method Summary collapse
Instance Method Details
#download(url, filename, dest_dir) ⇒ Object
18 19 20 21 22 23 |
# File 'lib/sudachi-installer/downloader.rb', line 18 def download(url, filename, dest_dir) FileUtils.mkdir_p(dest_dir) Down.download(url, destination: File.join(dest_dir, filename)) (File.join(dest_dir, filename), force: true) if filename.match?(/\.zip\z/i) end |
#expand(path, force: false) ⇒ Object
29 30 31 32 33 34 35 36 37 38 39 |
# File 'lib/sudachi-installer/downloader.rb', line 29 def (path, force: false) dir = File.dirname(path) Zip::File.open(path) { |zip| zip.each { |entry| dest = File.join(dir, entry.name) FileUtils.rm_rf dest if File.exist?(dest) && force entry.extract(File.join(dir, entry.name)) } } end |