Class: AbideDevUtils::Comply::ScanReport

Inherits:
Object
  • Object
show all
Defined in:
lib/abide_dev_utils/comply.rb

Overview

Contains multiple NodeScanReport objects

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#node_scan_reportsObject (readonly)

Returns the value of attribute node_scan_reports.



379
380
381
# File 'lib/abide_dev_utils/comply.rb', line 379

def node_scan_reports
  @node_scan_reports
end

Class Method Details

.fetch_report(name: 'comply_report.yaml') ⇒ Object



407
408
409
410
# File 'lib/abide_dev_utils/comply.rb', line 407

def self.fetch_report(name: 'comply_report.yaml')
  report = storage_bucket.file(name)
  report.download.read
end

.storage_bucketObject



403
404
405
# File 'lib/abide_dev_utils/comply.rb', line 403

def self.storage_bucket
  @storage_bucket ||= AbideDevUtils::GCloud.storage_bucket
end

.upload_report(report, name: 'comply_report.yaml') ⇒ Object



412
413
414
# File 'lib/abide_dev_utils/comply.rb', line 412

def self.upload_report(report, name: 'comply_report.yaml')
  storage_bucket.create_file(report, name)
end

Instance Method Details

#from_yaml(report) ⇒ Object



381
382
383
384
385
386
387
388
389
390
391
# File 'lib/abide_dev_utils/comply.rb', line 381

def from_yaml(report)
  @scan_report = if report.is_a? Hash
                   report
                 elsif File.file?(report)
                   File.open(report.to_s, 'r') { |f| YAML.safe_load(f.read) }
                 else
                   YAML.safe_load(report)
                 end
  @node_scan_reports = build_node_scan_reports
  self
end

#good_comparison?(report_comparison) ⇒ Boolean

Returns:

  • (Boolean)


429
430
431
432
433
434
435
436
437
438
439
440
441
442
443
444
445
446
447
448
# File 'lib/abide_dev_utils/comply.rb', line 429

def good_comparison?(report_comparison)
  good = true
  not_good = {}
  report_comparison.each do |node_report|
    node_name = node_report.keys[0]
    report = node_report[node_name]
    next if report[:diff].empty?

    not_good[node_name] = {}
    unless report.dig(:diff, :passing, :other).nil?
      good = false
      not_good[node_name][:new_not_passing] = report[:diff][:passing][:other]
    end
    unless report.dig(:diff, :failing, :self).nil?
      good = false
      not_good[node_name][:new_failing] = report[:diff][:failing][:self]
    end
  end
  [good, not_good]
end

#report_comparison(other, check_goodness: false) ⇒ Object



416
417
418
419
420
421
422
423
424
425
426
427
# File 'lib/abide_dev_utils/comply.rb', line 416

def report_comparison(other, check_goodness: false)
  comparison = []
  node_scan_reports.zip(other.node_scan_reports).each do |cr, lr|
    comparison << { cr.name => { diff: {}, node_presense: :new } } if lr.nil?
    comparison << { lr.name => { diff: {}, node_presense: :dropped } } if cr.nil?
    comparison << { cr.name => { diff: cr.diff(lr), node_presence: :same } } unless cr.nil? || lr.nil?
  end
  comparison.inject(&:merge)
  return good_comparison?(comparison) if check_goodness

  compairison
end

#to_hObject



393
394
395
396
397
# File 'lib/abide_dev_utils/comply.rb', line 393

def to_h
  node_scan_reports.each_with_object({}) do |node, h|
    h[node.name] = node.hash
  end
end

#to_yamlObject



399
400
401
# File 'lib/abide_dev_utils/comply.rb', line 399

def to_yaml
  to_h.to_yaml
end