Class: PuppetRakeTasks::DepChecker::Resolver

Inherits:
Object
  • Object
show all
Includes:
Helpers, Filter, Ignores, Incidents, Report
Defined in:
lib/puppet_rake_tasks/depchecker/resolver.rb,
lib/puppet_rake_tasks/depchecker/filter.rb,
lib/puppet_rake_tasks/depchecker/report.rb,
lib/puppet_rake_tasks/depchecker/ignores.rb,
lib/puppet_rake_tasks/depchecker/incidents.rb

Overview

Class to detect all puppet module dependency issues. It uses puppet module tool internals to detect all issues.

Defined Under Namespace

Modules: Filter, Ignores, Incidents, Report

Instance Attribute Summary

Attributes included from Report

#fail_on_error, #format, #output

Instance Method Summary collapse

Methods included from Report

#enrich_incident, #format_incident, #format_module_incidents, #report

Methods included from Helpers

compare_values, normalize_path, swat_hash

Methods included from Filter

#filter_incidents, #filter_module_incidents, #filtered

Methods included from Incidents

#incidents, #initialize_incidents

Methods included from Ignores

#collect_ignores_for_module, #ignore, #ignores, #ignores=, #ignores_for_module, #ignores_matches_incident

Constructor Details

#initialize(module_path = '.') ⇒ Resolver

Returns a new instance of Resolver.



21
22
23
# File 'lib/puppet_rake_tasks/depchecker/resolver.rb', line 21

def initialize(module_path = '.')
  @modulepath = Helpers.normalize_path(module_path)
end

Instance Method Details

#envObject

Returns the puppet module tool environment.



27
28
29
# File 'lib/puppet_rake_tasks/depchecker/resolver.rb', line 27

def env
  @env ||= Puppet::ModuleTool.environment_from_options(modulepath: modulepath_s)
end

#modulepathArray<String>

Returns the configured module paths.

Returns:

  • (Array<String>)

    configured module paths as an array.



46
47
48
# File 'lib/puppet_rake_tasks/depchecker/resolver.rb', line 46

def modulepath
  @modulepath ||= ['.']
end

#modulepath=(path) ⇒ Array<String>

Set the modulepath and normalize using Helpers.normalize_path When the module path changes, cached values are cleared

Parameters:

  • path (Array<String>, String)

    Module paths

Returns:

  • (Array<String>)

    configured and normalized module paths.



60
61
62
63
64
65
66
# File 'lib/puppet_rake_tasks/depchecker/resolver.rb', line 60

def modulepath=(path)
  unless path == @modulepath
    # reset the env and loaded modules when changing the modulepath
    reset_caches
  end
  @modulepath = Helpers.normalize_path(path)
end

#modulepath_sString

Return modulepath as a string

Returns:

  • (String)

    module paths joined with File::PATH_SEPARATOR



52
53
54
# File 'lib/puppet_rake_tasks/depchecker/resolver.rb', line 52

def modulepath_s
  @modulepath.flatten.join(File::PATH_SEPARATOR)
end

#modulesObject

Collect the installed modules using Puppet::ModuleTool.



33
34
35
# File 'lib/puppet_rake_tasks/depchecker/resolver.rb', line 33

def modules
  @modules ||= Puppet::ModuleTool::InstalledModules.new(env)
end

#reset_cachesObject

Clear all cached data (env, modules, incidents)



38
39
40
41
42
# File 'lib/puppet_rake_tasks/depchecker/resolver.rb', line 38

def reset_caches
  @env = nil
  @modules = nil
  @incidents = nil
end