Sha256: 61453d11b0098381de629ca93a186761590c5b1c779d049a9caae52c9ae03ad3

Contents?: true

Size: 817 Bytes

Versions: 2

Compression:

Stored size: 817 Bytes

Contents

require "albacore/albacoretask"
require "albacore/config/unzipconfig"
require "zip"
require "zip/filesystem"

class Unzip
  include Albacore::Task
  include Configuration::Unzip
  
  attr_reader   :force
  
  attr_accessor :destination, 
                :file

  def initialize
    super()
    update_attributes(unzip.to_hash)
  end
    
  def execute()
    unless @file
      fail_with_message("unzip requires #file")
      return
    end
  
    Zip::File.open(@file) do |zip|
      zip.each do |file|
        path = File.join(@destination, file.name)
        dir = File.dirname(path)
        
        FileUtils.mkdir_p(dir)
        File.delete(path) if (@force && File.file?(path))
        
        zip.extract(file, path) unless File.exist?(path)
      end
    end
  end
  
  def force
    @force = true
  end
end

Version data entries

2 entries across 2 versions & 1 rubygems

Version Path
albacore-1.0.0 lib/albacore/unzip.rb
albacore-1.0.0.rc.3 lib/albacore/unzip.rb