Class: InspecPlugins::CliReporter::Reporter::ControlForCliDisplay

Inherits:
Object
  • Object
show all
Extended by:
Forwardable
Defined in:
lib/plugins/inspec-reporter-cli/lib/inspec-reporter-cli/reporter.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(control_obj) ⇒ ControlForCliDisplay

Returns a new instance of ControlForCliDisplay.



303
304
305
# File 'lib/plugins/inspec-reporter-cli/lib/inspec-reporter-cli/reporter.rb', line 303

def initialize(control_obj)
  @control_obj = control_obj
end

Instance Attribute Details

#control_objObject (readonly)

Returns the value of attribute control_obj.



300
301
302
# File 'lib/plugins/inspec-reporter-cli/lib/inspec-reporter-cli/reporter.rb', line 300

def control_obj
  @control_obj
end

Instance Method Details

#anonymous?Boolean

Returns:

  • (Boolean)


307
308
309
# File 'lib/plugins/inspec-reporter-cli/lib/inspec-reporter-cli/reporter.rb', line 307

def anonymous?
  id.start_with?("(generated from ")
end

#failure_countObject



354
355
356
# File 'lib/plugins/inspec-reporter-cli/lib/inspec-reporter-cli/reporter.rb', line 354

def failure_count
  results.select { |r| r.status == "failed" }.size
end

#impact_stringObject



328
329
330
331
332
333
334
335
336
337
338
339
340
# File 'lib/plugins/inspec-reporter-cli/lib/inspec-reporter-cli/reporter.rb', line 328

def impact_string
  if anonymous?
    nil
  elsif impact.nil?
    "unknown"
  elsif results&.find { |r| r.status == "skipped" }
    "skipped"
  elsif results.empty? || results.all? { |r| r.status == "passed" }
    "passed"
  else
    "failed"
  end
end

#impact_string_for_result(result) ⇒ Object



342
343
344
345
346
347
348
349
350
351
352
# File 'lib/plugins/inspec-reporter-cli/lib/inspec-reporter-cli/reporter.rb', line 342

def impact_string_for_result(result)
  if result.status == "skipped"
    "skipped"
  elsif result.status == "passed"
    "passed"
  elsif impact.nil?
    "unknown"
  else
    "failed"
  end
end

#skipped_countObject



358
359
360
# File 'lib/plugins/inspec-reporter-cli/lib/inspec-reporter-cli/reporter.rb', line 358

def skipped_count
  results.select { |r| r.status == "skipped" }.size
end

#title_for_reportObject



311
312
313
314
315
316
317
318
319
320
321
322
323
324
325
326
# File 'lib/plugins/inspec-reporter-cli/lib/inspec-reporter-cli/reporter.rb', line 311

def title_for_report
  # if this is an anonymous control, just grab the resource title from any result entry
  return results.first.resource_title if anonymous?

  title_for_report = "#{id}: #{title || results.first.resource_title}"

  # we will not add any additional data to the title if there's only
  # zero or one test for this control.
  return title_for_report if results.nil? || results.size <= 1

  # append a failure summary if appropriate.
  title_for_report += " (#{failure_count} failed)" if failure_count > 0
  title_for_report += " (#{skipped_count} skipped)" if skipped_count > 0

  title_for_report
end