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.
Instance Method Summary collapse
- #anonymous? ⇒ Boolean
- #failure_count ⇒ Object
- #id ⇒ Object
- #impact ⇒ Object
- #impact_string ⇒ Object
- #impact_string_for_result(result) ⇒ Object
-
#initialize(control_hash) ⇒ Control
constructor
A new instance of Control.
- #results ⇒ Object
- #skipped_count ⇒ Object
- #title ⇒ Object
- #title_for_report ⇒ Object
Constructor Details
#initialize(control_hash) ⇒ Control
Returns a new instance of Control.
280 281 282 |
# File 'lib/inspec/reporters/cli.rb', line 280 def initialize(control_hash) @data = control_hash end |
Instance Attribute Details
#data ⇒ Object (readonly)
Returns the value of attribute data.
278 279 280 |
# File 'lib/inspec/reporters/cli.rb', line 278 def data @data end |
Instance Method Details
#anonymous? ⇒ Boolean
300 301 302 |
# File 'lib/inspec/reporters/cli.rb', line 300 def anonymous? id.start_with?('(generated from ') end |
#failure_count ⇒ Object
347 348 349 |
# File 'lib/inspec/reporters/cli.rb', line 347 def failure_count results.select { |r| r[:status] == 'failed' }.size end |
#id ⇒ Object
284 285 286 |
# File 'lib/inspec/reporters/cli.rb', line 284 def id data[:id] end |
#impact ⇒ Object
296 297 298 |
# File 'lib/inspec/reporters/cli.rb', line 296 def impact data[:impact] end |
#impact_string ⇒ Object
321 322 323 324 325 326 327 328 329 330 331 332 333 |
# File 'lib/inspec/reporters/cli.rb', line 321 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_result(result) ⇒ Object
335 336 337 338 339 340 341 342 343 344 345 |
# File 'lib/inspec/reporters/cli.rb', line 335 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
292 293 294 |
# File 'lib/inspec/reporters/cli.rb', line 292 def results data[:results] end |
#skipped_count ⇒ Object
351 352 353 |
# File 'lib/inspec/reporters/cli.rb', line 351 def skipped_count results.select { |r| r[:status] == 'skipped' }.size end |
#title ⇒ Object
288 289 290 |
# File 'lib/inspec/reporters/cli.rb', line 288 def title data[:title] end |
#title_for_report ⇒ Object
304 305 306 307 308 309 310 311 312 313 314 315 316 317 318 319 |
# File 'lib/inspec/reporters/cli.rb', line 304 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 |