Class: ComplianceEngine::EnvironmentLoader

Inherits:
Object
  • Object
show all
Defined in:
lib/compliance_engine/environment_loader.rb

Overview

Load compliance engine data from a Puppet environment

Direct Known Subclasses

Zip

Defined Under Namespace

Classes: Zip

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(*paths, fileclass: File, dirclass: Dir, zipfile_path: nil) ⇒ EnvironmentLoader

Initialize an EnvironmentLoader from the components of a Puppet ‘modulepath`

Parameters:

  • the paths to search for Puppet modules

  • (defaults to: File)

    the class to use for file operations (default: ‘File`)

  • (defaults to: Dir)

    the class to use for directory operations (default: ‘Dir`)

  • (defaults to: nil)

    the path to the zip file if loading from a zip archive

Raises:



14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
# File 'lib/compliance_engine/environment_loader.rb', line 14

def initialize(*paths, fileclass: File, dirclass: Dir, zipfile_path: nil)
  raise ArgumentError, 'No paths specified' if paths.empty?
  @modulepath ||= paths
  @zipfile_path = zipfile_path
  modules = paths.map do |path|
    dirclass.entries(path)
            .grep(%r{\A[a-z][a-z0-9_]*\Z})
            .select { |child| fileclass.directory?(File.join(path, child)) }
            .map { |child| File.join(path, child) }
            .sort
  rescue
    []
  end
  modules.flatten!
  @modules = modules.map { |path| ComplianceEngine::ModuleLoader.new(path, fileclass: fileclass, dirclass: dirclass, zipfile_path: @zipfile_path) }
end

Instance Attribute Details

#modulepathObject (readonly)

Returns the value of attribute modulepath.



31
32
33
# File 'lib/compliance_engine/environment_loader.rb', line 31

def modulepath
  @modulepath
end

#modulesObject (readonly)

Returns the value of attribute modules.



31
32
33
# File 'lib/compliance_engine/environment_loader.rb', line 31

def modules
  @modules
end

#zipfile_pathObject (readonly)

Returns the value of attribute zipfile_path.



31
32
33
# File 'lib/compliance_engine/environment_loader.rb', line 31

def zipfile_path
  @zipfile_path
end