Class: Packmule::Archiver::Zip

Inherits:
Object
  • Object
show all
Defined in:
lib/packmule/archiver.rb

Overview

Zipper

Class Method Summary collapse

Class Method Details

.create(options) ⇒ Object

Zips the stuff



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
# File 'lib/packmule/archiver.rb', line 42

def self.create(options)
  # Make sure the archive doesn't exist..
  if ::FileTest.exists? "./#{options[:filename]}.zip"
    puts "#{options[:filename]}.zip already exists, skipping"
    return false
  end

  # Get the needed Zip stuff
  gem 'rubyzip'
  require 'zip/zip'
  require 'zip/zipfilesystem'

  # Create the archive
  ::Zip::ZipFile.open("./#{options[:filename]}.zip", 'w') do |z|
    Dir["#{options[:dir]}/**/**"].each do |file|
      z.add(file.sub("#{options[:dir]}/", ''), file) if not options[:ignore].include?(file.sub("#{options[:dir]}/", ''))
    end # Dir
  end # Zip block
  
  puts " - #{options[:filename]}.zip created"
  return true
end