Class: ComplianceEngine::EnvironmentLoader::Zip

Inherits:
ComplianceEngine::EnvironmentLoader show all
Defined in:
lib/compliance_engine/environment_loader/zip.rb

Overview

Load compliance engine data from a zip file containing a Puppet environment

Instance Attribute Summary

Attributes inherited from ComplianceEngine::EnvironmentLoader

#modulepath, #modules, #zipfile_path

Instance Method Summary collapse

Constructor Details

#initialize(input, root: '/'.dup, load_dotfiles: true, name: nil) ⇒ Zip

Initialize a ComplianceEngine::EnvironmentLoader::Zip object from a zip file and an optional root directory.

Parameters:

  • input (String, ::Zip::File)

    either a filesystem path to a zip file, or an already-opened ::Zip::File (e.g. from Zip::File.open_buffer); when a ::Zip::File is passed, the caller owns its lifecycle

  • root (String) (defaults to: '/'.dup)

    a directory within the zip file to use as the root of the environment

  • load_dotfiles (Boolean) (defaults to: true)

    whether to load dotfiles; defaults to true to preserve the historical zip-loader behaviour of including all files

  • name (String, nil) (defaults to: nil)

    identifier used for modulepath and downstream cache keys; defaults to the zip’s #name (the path on disk, or “-” for buffer-opened zips). Pass an explicit value when loading a buffer-opened zip to keep cache keys unique and logs informative.



22
23
24
25
26
27
28
# File 'lib/compliance_engine/environment_loader/zip.rb', line 22

def initialize(input, root: '/'.dup, load_dotfiles: true, name: nil)
  zipfile = input.is_a?(::Zip::File) ? input : ::Zip::File.open(input)
  @modulepath = name || zipfile.name
  super(root, fileclass: zipfile.file, dirclass: zipfile.dir, zipfile_path: @modulepath, load_dotfiles: load_dotfiles)
ensure
  zipfile.close if zipfile && !input.is_a?(::Zip::File)
end