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
7 8 9 |
# File 'lib/archspec/baseline.rb', line 7 def self.empty(root: nil) new(Set.new, root: root) end |
.load(path, root:) ⇒ Object
11 12 13 14 15 16 17 18 19 20 |
# File 'lib/archspec/baseline.rb', line 11 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
22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 |
# File 'lib/archspec/baseline.rb', line 22 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
43 44 45 |
# File 'lib/archspec/baseline.rb', line 43 def include?(diagnostic) ids.include?(diagnostic.fingerprint(root: root)) end |