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

Inherits:
DiagnosticFormatter show all
Defined in:
lib/puppet/pops/validation.rb

Overview

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



302
303
304
305
306
307
308
# File 'lib/puppet/pops/validation.rb', line 302

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

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



312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
327
328
329
330
331
332
333
334
# File 'lib/puppet/pops/validation.rb', line 312

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