Module: Zip

Extended by:
Zip
Included in:
Zip
Defined in:
lib/apps/zip.rb

Class Method Summary collapse

Class Method Details

.export(zip_file, destination) ⇒ Object

exports a zip file to a destination directory zip_file full path to a zip file to be exported destination directory where the zip file contents are to be placed



11
12
13
14
15
16
# File 'lib/apps/zip.rb', line 11

def self.export zip_file, destination
  raise "#{zip_file} does not exist." unless(::File.exists?(zip_file))

  unzip(zip_file, destination) unless(Dir.exists?(destination))
  sleep(0.5)  # I guess we need to give the OS some time to get things in order?    
end

.publish(source_dir, destination, source_filelist = FileList.new('**/*')) ⇒ Object

publish a directory to a file path source_dir is the directory with the files to be published destination is the zip file path source_glob is a string or array of glob directives to specify files in source_dir to be publish source_glob defaults to ‘*/’ to publish all files in the source_dir



23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/apps/zip.rb', line 23

def self.publish source_dir, destination, source_filelist=FileList.new('**/*')
  Dir.mktmpdir do |dir|           # Build zip file locally
    tmp_file_name = "#{dir}/#{::File.basename(destination)}"
    
    zip(source_dir, source_filelist, tmp_file_name)
    
    destination_dir = ::File.dirname(destination)
    FileUtils.mkpath(destination_dir) unless(Dir.exists?(destination_dir))
    
    FileUtils.cp(tmp_file_name, destination)
  end
end