Class: Necropsy::Guardrail::Baseline
- Inherits:
-
Object
- Object
- Necropsy::Guardrail::Baseline
- Defined in:
- lib/necropsy/guardrail/baseline.rb
Instance Attribute Summary collapse
-
#fingerprints ⇒ Object
readonly
Returns the value of attribute fingerprints.
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #include?(finding) ⇒ Boolean
-
#initialize(path:, fingerprints:) ⇒ Baseline
constructor
A new instance of Baseline.
Constructor Details
#initialize(path:, fingerprints:) ⇒ Baseline
Returns a new instance of Baseline.
37 38 39 40 |
# File 'lib/necropsy/guardrail/baseline.rb', line 37 def initialize(path:, fingerprints:) @path = path @fingerprints = fingerprints end |
Instance Attribute Details
#fingerprints ⇒ Object (readonly)
Returns the value of attribute fingerprints.
9 10 11 |
# File 'lib/necropsy/guardrail/baseline.rb', line 9 def fingerprints @fingerprints end |
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/necropsy/guardrail/baseline.rb', line 9 def path @path end |
Class Method Details
.load(path) ⇒ Object
11 12 13 14 15 16 |
# File 'lib/necropsy/guardrail/baseline.rb', line 11 def self.load(path) return new(path: path, fingerprints: []) unless File.exist?(path) payload = YAML.load_file(path) || {} new(path: path, fingerprints: Array(payload['findings']).map { |finding| finding['fingerprint'] }) end |
.write(report, path:) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/necropsy/guardrail/baseline.rb', line 18 def self.write(report, path:) findings = report.findings.map do |finding| { 'fingerprint' => finding.fingerprint, 'classification' => finding.classification.to_s, 'confidence' => finding.confidence.to_s, 'node_id' => finding.node.id, 'file' => finding.node.file, 'line' => finding.node.line } end payload = { 'version' => 1, 'generated_at' => Time.now.utc.iso8601, 'findings' => findings } File.write(path, payload.to_yaml) end |
Instance Method Details
#include?(finding) ⇒ Boolean
42 43 44 |
# File 'lib/necropsy/guardrail/baseline.rb', line 42 def include?(finding) fingerprints.include?(finding.fingerprint) end |