Class: ArchSpec::Baseline
- Inherits:
-
Object
- Object
- ArchSpec::Baseline
- Defined in:
- lib/archspec/baseline.rb
Class Method Summary collapse
Instance Method Summary collapse
- #include?(diagnostic) ⇒ Boolean
-
#initialize(ids, root:) ⇒ Baseline
constructor
A new instance of Baseline.
Constructor Details
Class Method Details
.empty(root: nil) ⇒ Object
6 7 8 |
# File 'lib/archspec/baseline.rb', line 6 def self.empty(root: nil) new(Set.new, root: root) end |
.load(path, root:) ⇒ Object
10 11 12 13 14 15 16 17 18 19 |
# File 'lib/archspec/baseline.rb', line 10 def self.load(path, root:) return empty(root: root) unless path && File.exist?(path) document = YAML.safe_load_file(path, permitted_classes: [], aliases: false) || {} ids = Array(document["violations"]).filter_map do |entry| entry.is_a?(Hash) ? entry["id"] : entry end new(ids.to_set, root: root) end |
.write(path, diagnostics, root:) ⇒ Object
21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 |
# File 'lib/archspec/baseline.rb', line 21 def self.write(path, diagnostics, root:) payload = { "violations" => diagnostics.map do |diagnostic| { "id" => diagnostic.fingerprint(root: root), "rule" => diagnostic.rule, "path" => diagnostic.location.relative_path(root), "line" => diagnostic.location.line, "message" => diagnostic. } end } File.write(path, payload.to_yaml) end |
Instance Method Details
#include?(diagnostic) ⇒ Boolean
42 43 44 |
# File 'lib/archspec/baseline.rb', line 42 def include?(diagnostic) ids.include?(diagnostic.fingerprint(root: root)) end |