Module: PuppetRakeTasks::DepChecker::Resolver::Report

Extended by:
Helpers
Included in:
PuppetRakeTasks::DepChecker::Resolver
Defined in:
lib/puppet_rake_tasks/depchecker/report.rb

Overview

Prints stuff to stderr and optionally raises an error

Defined Under Namespace

Classes: DependencyError

Instance Attribute Summary collapse

Instance Method Summary collapse

Methods included from Helpers

compare_values, normalize_path, swat_hash

Instance Attribute Details

#fail_on_errorBoolean

Boolean indicating wether or not we will fail (raise error) when there are incidents.

Returns:

  • (Boolean)


36
37
38
# File 'lib/puppet_rake_tasks/depchecker/report.rb', line 36

def fail_on_error
  @fail_on_error ||= false
end

#formatString

Returns the format configured (or the default format)

Returns:

  • (String)

    string fed into sprintf.



29
30
31
32
# File 'lib/puppet_rake_tasks/depchecker/report.rb', line 29

def format
  @format ||= 'ERROR: module %<module_name>s: %<reason>s dependency %<name>s. '\
    "Wants: '%<version_constraint>s', got: '%<mod_details.installed_version>s'\n"
end

#outputObject



23
24
25
# File 'lib/puppet_rake_tasks/depchecker/report.rb', line 23

def output
  @output ||= $stderr
end

Instance Method Details

#enrich_incident(incident) ⇒ Hash

Adds extra information to the incident hash for reporting purposes.

Parameters:

  • incident (Hash)

    Incident to enrich.

Returns:

  • (Hash)

    copy of the incident with extra data and a default_proc assigned.



52
53
54
55
56
57
58
# File 'lib/puppet_rake_tasks/depchecker/report.rb', line 52

def enrich_incident(incident)
  incident = Helpers.swat_hash(incident)
  # For recent enough ruby versions, this default proc will just show missing
  # keys in stead of failing on them (when using sprintf).
  incident.default_proc = proc { |hash, key| hash[key] = "%<#{key}>s" }
  incident
end

#format_incident(info_hash) ⇒ Object

Format a single incident.

Parameters:

  • info_hash (Hash)

    hash with all information for the incident.



73
74
75
# File 'lib/puppet_rake_tasks/depchecker/report.rb', line 73

def format_incident(info_hash)
  output.puts(Kernel.format(format, enrich_incident(info_hash)))
end

#format_module_incidents(module_name, module_incidents) ⇒ Object

Format all incidents for a certain module.

Parameters:

  • module_name (String)

    name of the module the incidents are detected for.

  • module_incidents (Array<Hash>)

    All incidents.



63
64
65
66
67
68
69
# File 'lib/puppet_rake_tasks/depchecker/report.rb', line 63

def format_module_incidents(module_name, module_incidents)
  module_incidents.each do |incident|
    # Add the module_name to the incident
    info_hash = incident.merge(module_name: module_name)
    format_incident(info_hash)
  end
end

#reportObject

Gets all filtered incidents for all modules and reports them module by module.

Raises:

  • (DependencyError)

    if there are any issues detected and fail_on_error is enabled (true)



42
43
44
45
46
47
# File 'lib/puppet_rake_tasks/depchecker/report.rb', line 42

def report
  filtered.each do |module_name, module_incidents|
    format_module_incidents(module_name, module_incidents)
  end
  raise DependencyError.new('Module errors found', filtered) unless filtered.empty? || !fail_on_error
end