Sha256: b167d708adfc9cde6c2fee50a4342c30467fe115e830f3c25e3f5ed3896a4de8

Contents?: true

Size: 1.48 KB

Versions: 88

Compression:

Stored size: 1.48 KB

Contents

require "zip/zipfilesystem"

module CFoundry
  # Generic Zpi API. Uses rubyzip underneath, but may be changed in the future
  # to use system zip command if necessary.
  module Zip
    # Directory entries to exclude from packing.
    PACK_EXCLUSION_GLOBS = ['..', '.', '*~', '#*#', '*.log']

    module_function

    # Get the entries in the zip file. Returns an array of the entire
    # contents, recursively (not just top-level).
    def entry_lines(file)
      entries = []
      ::Zip::ZipFile.foreach(file) do |zentry|
        entries << zentry
      end
      entries
    end

    # Unpack a zip +file+ to directory +dest+.
    def unpack(file, dest)
      ::Zip::ZipFile.foreach(file) do |zentry|
        epath = "#{dest}/#{zentry}"
        dirname = File.dirname(epath)
        FileUtils.mkdir_p(dirname) unless File.exists?(dirname)
        zentry.extract(epath) unless File.exists?(epath)
      end
    end

    # Determine what files in +dir+ to pack.
    def files_to_pack(dir)
      Dir.glob("#{dir}/**/*", File::FNM_DOTMATCH).select do |f|
        File.exists?(f) &&
          PACK_EXCLUSION_GLOBS.none? do |e|
            File.fnmatch(e, File.basename(f))
          end
      end
    end

    # Package directory +dir+ as file +zipfile+.
    def pack(dir, zipfile)
      files = files_to_pack(dir)
      return false if files.empty?

      ::Zip::ZipFile.open(zipfile, true) do |zf|
        files.each do |f|
          zf.add(f.sub("#{dir}/",''), f)
        end
      end

      true
    end
  end
end

Version data entries

88 entries across 88 versions & 2 rubygems

Version Path
cfoundry-0.4.0 lib/cfoundry/zip.rb
cfoundry-0.3.61 lib/cfoundry/zip.rb
cfoundry-0.3.60 lib/cfoundry/zip.rb
cfoundry-0.3.59 lib/cfoundry/zip.rb
cfoundry-0.3.58 lib/cfoundry/zip.rb
cfoundry-0.3.57 lib/cfoundry/zip.rb
cfoundry-0.3.56 lib/cfoundry/zip.rb
cfoundry-0.3.55 lib/cfoundry/zip.rb
cfoundry-0.3.54 lib/cfoundry/zip.rb
cfoundry-0.3.53 lib/cfoundry/zip.rb
cfoundry-0.3.52 lib/cfoundry/zip.rb
cfoundry-0.3.51 lib/cfoundry/zip.rb
cfoundry-0.3.50 lib/cfoundry/zip.rb
cfoundry-0.3.49 lib/cfoundry/zip.rb
cfoundry-0.3.48 lib/cfoundry/zip.rb
cfoundry-0.3.47 lib/cfoundry/zip.rb
cfoundry-0.3.46 lib/cfoundry/zip.rb
cfoundry-0.3.45 lib/cfoundry/zip.rb
cfoundry-0.3.44 lib/cfoundry/zip.rb
cfoundry-0.3.43 lib/cfoundry/zip.rb