Class: Puppet::Pops::Validation::DiagnosticFormatter Private
- Defined in:
- lib/puppet/pops/validation.rb
Overview
This class is part of a private API. You should avoid using this class if possible, as it may be removed or be changed in the future.
Formats a diagnostic for output. Produces a diagnostic output typical for a compiler (suitable for interpretation by tools) The format is: ‘file:line:pos: Message`, where pos, line and file are included if available.
Direct Known Subclasses
Instance Method Summary collapse
- #format(diagnostic) ⇒ Object private
- #format_location(diagnostic) ⇒ Object private
- #format_message(diagnostic) ⇒ Object private
-
#format_severity(diagnostic) ⇒ Object
private
This produces “Deprecation notice: ” prefix if the diagnostic has :deprecation severity, otherwise “”.
Instance Method Details
#format(diagnostic) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
269 270 271 |
# File 'lib/puppet/pops/validation.rb', line 269 def format diagnostic "#{format_location(diagnostic)} #{format_severity(diagnostic)}#{(diagnostic)}" end |
#format_location(diagnostic) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
286 287 288 289 290 291 292 293 294 295 296 297 298 299 300 301 302 303 |
# File 'lib/puppet/pops/validation.rb', line 286 def format_location diagnostic file = diagnostic.file file = (file.is_a?(String) && file.empty?) ? nil : file line = pos = nil if diagnostic.source_pos line = diagnostic.source_pos.line pos = diagnostic.source_pos.pos end if file && line && pos "#{file}:#{line}:#{pos}:" elsif file && line "#{file}:#{line}:" elsif file "#{file}:" else "" end end |
#format_message(diagnostic) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
273 274 275 |
# File 'lib/puppet/pops/validation.rb', line 273 def diagnostic diagnostic.issue.format(diagnostic.arguments) end |
#format_severity(diagnostic) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Note that it is not a good idea to use Puppet.deprecation_warning as it is for internal deprecation.
This produces “Deprecation notice: ” prefix if the diagnostic has :deprecation severity, otherwise “”. The idea is that all other diagnostics are emitted with the methods Puppet.err (or an exception), and Puppet.warning.
282 283 284 |
# File 'lib/puppet/pops/validation.rb', line 282 def format_severity diagnostic diagnostic.severity == :deprecation ? "Deprecation notice: " : "" end |