Class: AbideDevUtils::XCCDF::Diff::BenchmarkDiff
- Inherits:
-
Object
- Object
- AbideDevUtils::XCCDF::Diff::BenchmarkDiff
- Defined in:
- lib/abide_dev_utils/xccdf/diff.rb
Overview
Class for benchmark diffs
Instance Attribute Summary collapse
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#other ⇒ Object
readonly
Returns the value of attribute other.
-
#this ⇒ Object
readonly
Returns the value of attribute this.
Instance Method Summary collapse
- #diff ⇒ Object
- #diff_raw ⇒ Object
- #diff_rules ⇒ Object
- #diff_rules_raw ⇒ Object
-
#initialize(xml1, xml2, opts = {}) ⇒ BenchmarkDiff
constructor
A new instance of BenchmarkDiff.
Constructor Details
#initialize(xml1, xml2, opts = {}) ⇒ BenchmarkDiff
Returns a new instance of BenchmarkDiff.
29 30 31 32 33 |
# File 'lib/abide_dev_utils/xccdf/diff.rb', line 29 def initialize(xml1, xml2, opts = {}) @this = new_benchmark(xml1) @other = new_benchmark(xml2) @opts = opts end |
Instance Attribute Details
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
24 25 26 |
# File 'lib/abide_dev_utils/xccdf/diff.rb', line 24 def opts @opts end |
#other ⇒ Object (readonly)
Returns the value of attribute other.
24 25 26 |
# File 'lib/abide_dev_utils/xccdf/diff.rb', line 24 def other @other end |
#this ⇒ Object (readonly)
Returns the value of attribute this.
24 25 26 |
# File 'lib/abide_dev_utils/xccdf/diff.rb', line 24 def this @this end |
Instance Method Details
#diff ⇒ Object
[View source]
39 40 41 42 |
# File 'lib/abide_dev_utils/xccdf/diff.rb', line 39 def diff warn 'Full benchmark diff is not yet implemented, return rules diff for now' diff_rules end |
#diff_raw ⇒ Object
[View source]
35 36 37 |
# File 'lib/abide_dev_utils/xccdf/diff.rb', line 35 def diff_raw @diff_raw ||= @this.diff(@other) end |
#diff_rules ⇒ Object
[View source]
48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/abide_dev_utils/xccdf/diff.rb', line 48 def diff_rules return diff_rules_raw if opts[:raw] return [] if diff_rules_raw.all? { |r| r.type == :equal } diff_hash = { from: @this.to_s, to: @other.to_s, rules: {} } diff_rules_raw.each do |rule| diff_hash[:rules][rule.type] ||= [] case rule.type when :added diff_hash[:rules][rule.type] << { number: rule.new_value.number.to_s, title: rule.new_value.title.to_s } when :removed diff_hash[:rules][rule.type] << { number: rule.old_value.number.to_s, title: rule.old_value.title.to_s } else rd_hash = {} rd_hash[:from] = "#{rule.old_value&.number} #{rule.old_value&.title}" if rule.old_value rd_hash[:to] = "#{rule.new_value&.number} #{rule.new_value&.title}" if rule.new_value changes = rule.details.transform_values { |v| v.is_a?(Array) ? v.map(&:to_s) : v.to_s } if opts[:ignore_changed_properties] changes.delete_if { |k, _| opts[:ignore_changed_properties].include?(k.to_s) } next if changes.empty? # Skip entirely if all changed filtered out end rd_hash[:changes] = changes unless changes.empty? diff_hash[:rules][rule.type] << rd_hash end end unless opts[:no_stats] stats_hash = {} diff_hash[:rules].each do |type, rules| stats_hash[type] = rules.size end diff_hash[:stats] = stats_hash unless stats_hash.empty? end diff_hash end |
#diff_rules_raw ⇒ Object
[View source]
44 45 46 |
# File 'lib/abide_dev_utils/xccdf/diff.rb', line 44 def diff_rules_raw @diff_rules_raw ||= @this.diff_only_rules(@other) end |