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) ⇒ EnvironmentLoader

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

Parameters:

  • paths (Array)

    the paths to search for Puppet modules

  • fileclass (File) (defaults to: File)

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

  • dirclass (Dir) (defaults to: Dir)

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

Raises:

  • (ArgumentError)


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

def initialize(*paths, fileclass: File, dirclass: Dir)
  raise ArgumentError, 'No paths specified' if paths.empty?
  @modulepath ||= paths
  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) }
  rescue
    []
  end
  modules.flatten!
  @modules = modules.map { |path| ComplianceEngine::ModuleLoader.new(path, fileclass: fileclass, dirclass: dirclass) }
end

Instance Attribute Details

#modulepathObject (readonly)

Returns the value of attribute modulepath.



28
29
30
# File 'lib/compliance_engine/environment_loader.rb', line 28

def modulepath
  @modulepath
end

#modulesObject (readonly)

Returns the value of attribute modules.



28
29
30
# File 'lib/compliance_engine/environment_loader.rb', line 28

def modules
  @modules
end