Class: AbideDevUtils::XCCDF::Diff::BenchmarkDiff
- Inherits:
-
Object
- Object
- AbideDevUtils::XCCDF::Diff::BenchmarkDiff
- Includes:
- BenchmarkPropertyDiff
- Defined in:
- lib/abide_dev_utils/xccdf/diff.rb,
lib/abide_dev_utils/xccdf/diff/benchmark.rb
Overview
Class for benchmark diffs
Constant Summary collapse
- DEFAULT_OPTS =
{ only_classes: %w[rule], }.freeze
- LVL_PROF_DEFAULT =
Used for filtering by level and profile
[nil, nil].freeze
Constants included from BenchmarkPropertyDiff
AbideDevUtils::XCCDF::Diff::BenchmarkPropertyDiff::DEFAULT_PROPERTY_DIFF_OPTS
Instance Attribute Summary collapse
-
#opts ⇒ Object
readonly
Returns the value of attribute opts.
-
#other ⇒ Object
readonly
Returns the value of attribute other.
-
#self ⇒ Object
readonly
Returns the value of attribute self.
Instance Method Summary collapse
-
#diff(new: false) ⇒ Object
Returns a diff of the changes from the “self” xml (xml1) to the “other” xml (xml2) This function is memoized because the diff operation is expensive.
-
#from_benchmark ⇒ Object
Hash of data about the “self” benchmark and the diff parameters.
-
#initialize(xml1, xml2, opts = {}) ⇒ BenchmarkDiff
constructor
A new instance of BenchmarkDiff.
-
#levels ⇒ Object
All levels that numbered children have been filtered on.
- #method_missing(method_name, *args, &block) ⇒ Object
-
#number_title_diff ⇒ Object
Returns the output of a NumberTitleDiff object’s diff function based on self_numbered_children and other_numbered_children.
-
#numbered_children_title_diff ⇒ Object
Basic title diff.
-
#other_numbered_children ⇒ Object
Memoized getter for all “numbered” children for the “other” benchmark based on optional filters in opts.
-
#profiles ⇒ Object
All profiles that numbered children have been filtered on.
- #properties_to_diff ⇒ Object
- #respond_to_missing?(method_name, include_private = false) ⇒ Boolean
-
#self_numbered_children ⇒ Object
Memoized getter for all “numbered” children for the “self” benchmark based on optional filters in opts.
- #title_version ⇒ Object
-
#to_benchmark ⇒ Object
Hash of data about the “other” benchmark and the diff parameters.
Methods included from BenchmarkPropertyDiff
#add_other_rule_val, #add_rule_val, #add_self_rule_val, #find_most_similar, #max_digest_similarities, #maxed_digest_similarities, #most_similar, #other_rule_vals, #rule_property_similarity, #safe_rule_prop, #same_rule?, #self_rule_vals
Constructor Details
#initialize(xml1, xml2, opts = {}) ⇒ BenchmarkDiff
Returns a new instance of BenchmarkDiff.
27 28 29 30 31 |
# File 'lib/abide_dev_utils/xccdf/diff/benchmark.rb', line 27 def initialize(benchmark_a, benchmark_b, opts = {}) @benchmark_a = benchmark_a @benchmark_b = benchmark_b @opts = opts end |
Dynamic Method Handling
This class handles dynamic methods through the method_missing method
#method_missing(method_name, *args, &block) ⇒ Object
35 36 37 38 39 40 41 42 43 |
# File 'lib/abide_dev_utils/xccdf/diff/benchmark.rb', line 35 def method_missing(method_name, *args, &block) if opts.key?(method_name) opts[method_name] elsif @diff&.key?(method_name) @diff[method_name] else super end end |
Instance Attribute Details
#opts ⇒ Object (readonly)
Returns the value of attribute opts.
15 16 17 |
# File 'lib/abide_dev_utils/xccdf/diff/benchmark.rb', line 15 def opts @opts end |
#other ⇒ Object (readonly)
Returns the value of attribute other.
15 16 17 |
# File 'lib/abide_dev_utils/xccdf/diff/benchmark.rb', line 15 def other @other end |
#self ⇒ Object (readonly)
Returns the value of attribute self.
15 16 17 |
# File 'lib/abide_dev_utils/xccdf/diff/benchmark.rb', line 15 def self @self end |
Instance Method Details
#diff(new: false) ⇒ Object
Returns a diff of the changes from the “self” xml (xml1) to the “other” xml (xml2) This function is memoized because the diff operation is expensive. To run the diff operation again, set the ‘new` parameter to `true` return [Hash] the diff in hash format
103 104 105 106 107 108 109 |
# File 'lib/abide_dev_utils/xccdf/diff/benchmark.rb', line 103 def diff(new: false) return @diff if @diff && !new @diff = {} @diff[:number_title] = number_title_diff { from: from_benchmark, to: to_benchmark, diff: @diff } end |
#from_benchmark ⇒ Object
Hash of data about the “self” benchmark and the diff parameters
79 80 81 |
# File 'lib/abide_dev_utils/xccdf/diff/benchmark.rb', line 79 def from_benchmark @from_benchmark ||= from_to_hash(@self) end |
#levels ⇒ Object
All levels that numbered children have been filtered on
89 90 91 |
# File 'lib/abide_dev_utils/xccdf/diff/benchmark.rb', line 89 def levels @levels.flatten.uniq.empty? ? [:all] : @levels.flatten.uniq end |
#number_title_diff ⇒ Object
Returns the output of a NumberTitleDiff object’s diff function based on self_numbered_children and other_numbered_children
74 75 76 |
# File 'lib/abide_dev_utils/xccdf/diff/benchmark.rb', line 74 def number_title_diff NumberTitleDiff.new(self_numbered_children, other_numbered_children).diff end |
#numbered_children_title_diff ⇒ Object
Basic title diff
66 67 68 69 70 71 |
# File 'lib/abide_dev_utils/xccdf/diff/benchmark.rb', line 66 def numbered_children_title_diff { self: self_numbered_children.map { |c| c.title.to_s } - other_numbered_children.map { |c| c.title.to_s }, other: other_numbered_children.map { |c| c.title.to_s } - self_numbered_children.map { |c| c.title.to_s }, } end |
#other_numbered_children ⇒ Object
Memoized getter for all “numbered” children for the “other” benchmark based on optional filters in opts
58 59 60 61 62 63 |
# File 'lib/abide_dev_utils/xccdf/diff/benchmark.rb', line 58 def other_numbered_children @other_numbered_children ||= find_all_numbered_children(@other, only_classes: opts[:only_classes], level: opts[:level], profile: opts[:profile]) end |
#profiles ⇒ Object
All profiles that numbered children have been filtered on
94 95 96 |
# File 'lib/abide_dev_utils/xccdf/diff/benchmark.rb', line 94 def profiles(profile: nil) @profiles ||= diff_profiles(profile: profile) end |
#properties_to_diff ⇒ Object
172 173 174 |
# File 'lib/abide_dev_utils/xccdf/diff.rb', line 172 def properties_to_diff @properties_to_diff ||= %i[title version profiles] end |
#respond_to_missing?(method_name, include_private = false) ⇒ Boolean
45 46 47 |
# File 'lib/abide_dev_utils/xccdf/diff/benchmark.rb', line 45 def respond_to_missing?(method_name, include_private = false) opts.key?(method_name) || @diff&.key?(method_name) || super end |
#self_numbered_children ⇒ Object
Memoized getter for all “numbered” children for the “self” benchmark based on optional filters in opts
50 51 52 53 54 55 |
# File 'lib/abide_dev_utils/xccdf/diff/benchmark.rb', line 50 def self_numbered_children @self_numbered_children ||= find_all_numbered_children(@self, only_classes: opts[:only_classes], level: opts[:level], profile: opts[:profile]) end |
#title_version ⇒ Object
176 177 178 |
# File 'lib/abide_dev_utils/xccdf/diff.rb', line 176 def title_version @title_version ||= diff_title_version end |
#to_benchmark ⇒ Object
Hash of data about the “other” benchmark and the diff parameters
84 85 86 |
# File 'lib/abide_dev_utils/xccdf/diff/benchmark.rb', line 84 def to_benchmark @to_benchmark ||= from_to_hash(@other) end |