Class: StartProject::Downloader

Inherits:
Object
  • Object
show all
Defined in:
lib/start_project/downloader.rb

Overview

Manages the downloading and unzipping the file

Class Method Summary collapse

Class Method Details

.download(source) ⇒ Object

Downloads the relevant zip and stores it in a file called temp.zip



11
12
13
14
15
# File 'lib/start_project/downloader.rb', line 11

def self.download(source)
  open("temp.zip",'wb') do |fo|
    fo.print open(source).read
  end
end

.unzip_file(destination) ⇒ Object

Unzip the file into a directory specified in the intitial call to the app via the -n (–name option)



18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/start_project/downloader.rb', line 18

def self.unzip_file (destination)
  orig_name = ""
  Zip::ZipFile.open("temp.zip") { |zip_file|
   zip_file.each { |f|
     f_path=File.join("./", f.name)
     orig_name = f_path.split('/')[1]
     FileUtils.mkdir_p(File.dirname(f_path))
     zip_file.extract(f, f_path) unless File.exist?(f_path)
   }
  }
  File.rename(orig_name, destination)
  File.delete("temp.zip")
end