Class: Inspec::Reporters::CLI::Control
- Inherits:
-
Object
- Object
- Inspec::Reporters::CLI::Control
- Defined in:
- lib/inspec/reporters/cli.rb
Instance Attribute Summary collapse
-
#data ⇒ Object
readonly
Returns the value of attribute data.
-
#enhanced_outcomes ⇒ Object
Returns the value of attribute enhanced_outcomes.
Instance Method Summary collapse
- #anonymous? ⇒ Boolean
- #failure_count ⇒ Object
- #id ⇒ Object
- #impact ⇒ Object
- #impact_string ⇒ Object
- #impact_string_for_enhanced_outcomes ⇒ Object
- #impact_string_for_result(result) ⇒ Object
-
#initialize(control_hash) ⇒ Control
constructor
A new instance of Control.
- #results ⇒ Object
- #skipped_count ⇒ Object
- #source_location ⇒ Object
- #status ⇒ Object
- #title ⇒ Object
- #title_for_report ⇒ Object
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
#data ⇒ Object (readonly)
Returns the value of attribute data.
431 432 433 |
# File 'lib/inspec/reporters/cli.rb', line 431 def data @data end |
#enhanced_outcomes ⇒ Object
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
458 459 460 |
# File 'lib/inspec/reporters/cli.rb', line 458 def anonymous? id.start_with?("(generated from ") end |
#failure_count ⇒ Object
516 517 518 |
# File 'lib/inspec/reporters/cli.rb', line 516 def failure_count results.select { |r| r[:status] == "failed" }.size end |
#id ⇒ Object
438 439 440 |
# File 'lib/inspec/reporters/cli.rb', line 438 def id data[:id] end |
#impact ⇒ Object
450 451 452 |
# File 'lib/inspec/reporters/cli.rb', line 450 def impact data[:impact] end |
#impact_string ⇒ Object
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_outcomes ⇒ Object
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 |
#results ⇒ Object
446 447 448 |
# File 'lib/inspec/reporters/cli.rb', line 446 def results data[:results] end |
#skipped_count ⇒ Object
520 521 522 |
# File 'lib/inspec/reporters/cli.rb', line 520 def skipped_count results.select { |r| r[:status] == "skipped" }.size end |
#source_location ⇒ Object
454 455 456 |
# File 'lib/inspec/reporters/cli.rb', line 454 def source_location data[:source_location] end |
#status ⇒ Object
462 463 464 |
# File 'lib/inspec/reporters/cli.rb', line 462 def status data[:status] end |
#title ⇒ Object
442 443 444 |
# File 'lib/inspec/reporters/cli.rb', line 442 def title data[:title] end |
#title_for_report ⇒ Object
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 |