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
-
#fail_on_error ⇒ Boolean
Boolean indicating wether or not we will fail (raise error) when there are incidents.
-
#format ⇒ String
Returns the format configured (or the default format).
- #output ⇒ Object
Instance Method Summary collapse
-
#enrich_incident(incident) ⇒ Hash
Adds extra information to the incident hash for reporting purposes.
-
#format_incident(info_hash) ⇒ Object
Format a single incident.
-
#format_module_incidents(module_name, module_incidents) ⇒ Object
Format all incidents for a certain module.
-
#report ⇒ Object
Gets all filtered incidents for all modules and reports them module by module.
Methods included from Helpers
compare_values, normalize_path, swat_hash
Instance Attribute Details
#fail_on_error ⇒ Boolean
Boolean indicating wether or not we will fail (raise error) when there are incidents.
36 37 38 |
# File 'lib/puppet_rake_tasks/depchecker/report.rb', line 36 def fail_on_error @fail_on_error ||= false end |
#format ⇒ String
Returns the format configured (or the default format)
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 |
#output ⇒ Object
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.
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.
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.
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 |
#report ⇒ Object
Gets all filtered incidents for all modules and reports them module by module.
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 |