module PuppetRakeTasks::DepChecker::Resolver::Report

Prints stuff to `stderr` and optionally raises an error

Attributes

fail_on_error[W]
format[W]
output[W]

Public Instance Methods

enrich_incident(incident) click to toggle source

Adds extra information to the incident hash for reporting purposes. @param incident [Hash] Incident to enrich. @return [Hash] copy of the incident with extra data and a default_proc assigned.

# 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
fail_on_error() click to toggle source

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

# File lib/puppet_rake_tasks/depchecker/report.rb, line 36
def fail_on_error
  @fail_on_error ||= false
end
format() click to toggle source

Returns the format configured (or the default format) @return [String] string fed into sprintf.

# 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
format_incident(info_hash) click to toggle source

Format a single incident. @param info_hash [Hash] hash with all information for the incident.

# 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) click to toggle source

Format all incidents for a certain module. @param module_name [String] name of the module the incidents are detected for. @param module_incidents [Array<Hash>] All incidents.

# 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
output() click to toggle source
# File lib/puppet_rake_tasks/depchecker/report.rb, line 23
def output
  @output ||= $stderr
end
report() click to toggle source

Gets all filtered incidents for all modules and reports them module by module. @raise [DependencyError] if there are any issues detected and `fail_on_error` is enabled (`true`)

# 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