Module: Makit::ZipUtility

Defined in:
lib/makit/zip_utility.rb

Defined Under Namespace

Classes: Error

Class Method Summary collapse

Class Method Details

.create_from_directory(source_dir:, zip_path:, exclude_pattern: "*.pdb") ⇒ Object

Creates a zip file from a directory, preserving directory structure. Excludes files matching the exclude_pattern from the archive.

Examples:

Makit::ZipUtility.create_from_directory(
  source_dir: "artifacts/Musco.Aim3.AspNet.Host",
  zip_path: "artifacts/Musco.Aim3.AspNet.Host.zip"
)
Makit::ZipUtility.create_from_directory(
  source_dir: "artifacts/build",
  zip_path: "artifacts/build.zip",
  exclude_pattern: "*.{pdb,log}"
)

Parameters:

  • source_dir (String)

    The directory to zip

  • zip_path (String)

    The output zip file path

  • exclude_pattern (String) (defaults to: "*.pdb")

    File pattern to exclude (default: “*.pdb”) Supports glob patterns like “*.pdb”, “*.pdb,log”, “*/.tmp”

Raises:

  • (Error)

    If source directory doesn’t exist or zip creation fails



30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
# File 'lib/makit/zip_utility.rb', line 30

def self.create_from_directory(source_dir:, zip_path:, exclude_pattern: "*.pdb")
  source_dir = File.expand_path(source_dir)
  zip_path = File.expand_path(zip_path)

  unless Dir.exist?(source_dir)
    raise Error, "Source directory does not exist: #{source_dir}"
  end

  # Delete existing zip if it exists
  File.delete(zip_path) if File.exist?(zip_path)

  # Use RubyZip gem (cross-platform, no shell commands needed)
  create_zip_with_rubyzip(source_dir, zip_path, exclude_pattern)

  unless File.exist?(zip_path)
    raise Error, "Failed to create zip file: #{zip_path}"
  end

  zip_path
end