Class: Inspec::Reporters::CLI::Control

Inherits:
Object
  • Object
show all
Defined in:
lib/inspec/reporters/cli.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(control_hash) ⇒ Control

Returns a new instance of Control.



434
435
436
# File 'lib/inspec/reporters/cli.rb', line 434

def initialize(control_hash)
  @data = control_hash
end

Instance Attribute Details

#dataObject (readonly)

Returns the value of attribute data.



431
432
433
# File 'lib/inspec/reporters/cli.rb', line 431

def data
  @data
end

#enhanced_outcomesObject

Returns the value of attribute enhanced_outcomes.



432
433
434
# File 'lib/inspec/reporters/cli.rb', line 432

def enhanced_outcomes
  @enhanced_outcomes
end

Instance Method Details

#anonymous?Boolean

Returns:

  • (Boolean)


458
459
460
# File 'lib/inspec/reporters/cli.rb', line 458

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

#failure_countObject



516
517
518
# File 'lib/inspec/reporters/cli.rb', line 516

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

#idObject



438
439
440
# File 'lib/inspec/reporters/cli.rb', line 438

def id
  data[:id]
end

#impactObject



450
451
452
# File 'lib/inspec/reporters/cli.rb', line 450

def impact
  data[:impact]
end

#impact_stringObject



490
491
492
493
494
495
496
497
498
499
500
501
502
# File 'lib/inspec/reporters/cli.rb', line 490

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

#impact_string_for_enhanced_outcomesObject



482
483
484
485
486
487
488
# File 'lib/inspec/reporters/cli.rb', line 482

def impact_string_for_enhanced_outcomes
  if impact.nil?
    "unknown"
  else
    status
  end
end

#impact_string_for_result(result) ⇒ Object



504
505
506
507
508
509
510
511
512
513
514
# File 'lib/inspec/reporters/cli.rb', line 504

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

#resultsObject



446
447
448
# File 'lib/inspec/reporters/cli.rb', line 446

def results
  data[:results]
end

#skipped_countObject



520
521
522
# File 'lib/inspec/reporters/cli.rb', line 520

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

#source_locationObject



454
455
456
# File 'lib/inspec/reporters/cli.rb', line 454

def source_location
  data[:source_location]
end

#statusObject



462
463
464
# File 'lib/inspec/reporters/cli.rb', line 462

def status
  data[:status]
end

#titleObject



442
443
444
# File 'lib/inspec/reporters/cli.rb', line 442

def title
  data[:title]
end

#title_for_reportObject



466
467
468
469
470
471
472
473
474
475
476
477
478
479
480
# File 'lib/inspec/reporters/cli.rb', line 466

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