Class: Puppet::Pops::Validation::DiagnosticFormatterPuppetStyle Private

Inherits:
DiagnosticFormatter show all
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.

Produces a diagnostic output in the “puppet style”, where the location is appended with an “at …” if the location is known.

Instance Method Summary collapse

Methods inherited from DiagnosticFormatter

#format_message, #format_severity

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.



310
311
312
313
314
315
316
# File 'lib/puppet/pops/validation.rb', line 310

def format diagnostic
  if (location = format_location diagnostic) != ""
    "#{format_severity(diagnostic)}#{format_message(diagnostic)}#{location}"
  else
    format_message(diagnostic)
  end
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.

The somewhat (machine) unusable format in current use by puppet. have to be used here for backwards compatibility.



320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
335
336
337
338
339
340
341
342
# File 'lib/puppet/pops/validation.rb', line 320

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
    " at #{file}:#{line}:#{pos}"
  elsif file && line
    " at #{file}:#{line}"
  elsif line && pos
    " at line #{line}:#{pos}"
  elsif line
    " at line #{line}"
  elsif file
    " in #{file}"
  else
    ""
  end
end