Class: Hashira::CI::Baseline
- Inherits:
-
Object
- Object
- Hashira::CI::Baseline
- Defined in:
- lib/hashira/ci/baseline.rb
Constant Summary collapse
- SCHEMA_VERSION =
4
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
- .load(path, analyzers: [], targets: []) ⇒ Object
- .read(path) ⇒ Object
- .scored(recorded) ⇒ Object
- .trouble(path) ⇒ Object
Instance Method Summary collapse
- #analyzers ⇒ Object
- #edges ⇒ Object
- #exist? ⇒ Boolean
- #findings ⇒ Object
- #findings? ⇒ Boolean
-
#initialize(path, recorded, scope = Hashira::CI::Scope.none) ⇒ Baseline
constructor
A new instance of Baseline.
- #packaging ⇒ Object
- #targets ⇒ Object
- #wanted ⇒ Object
- #write(edges, findings, packaging:) ⇒ Object
Constructor Details
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
30 31 32 |
# File 'lib/hashira/ci/baseline.rb', line 30 def path @path end |
Class Method Details
.load(path, analyzers: [], targets: []) ⇒ Object
8 9 10 |
# File 'lib/hashira/ci/baseline.rb', line 8 def self.load(path, analyzers: [], targets: []) new(path, read(path), Hashira::CI::Scope.new(analyzers:, targets:)) end |
.read(path) ⇒ Object
12 13 14 15 16 |
# File 'lib/hashira/ci/baseline.rb', line 12 def self.read(path) return {} unless path && File.exist?(path) recorded = JSON.parse(File.read(path)) recorded.is_a?(Hash) ? recorded : raise(JSON::ParserError, "its top level is a list, not an object") end |
.scored(recorded) ⇒ Object
38 |
# File 'lib/hashira/ci/baseline.rb', line 38 def self.scored(recorded) = recorded.is_a?(Array) ? recorded.to_h { [it, nil] } : recorded |
.trouble(path) ⇒ Object
18 19 20 21 22 |
# File 'lib/hashira/ci/baseline.rb', line 18 def self.trouble(path) read(path) && nil rescue JSON::ParserError, SystemCallError => error "#{path} is not a usable baseline — #{error..lines.first.strip}. Re-record it with --update-baseline" end |
Instance Method Details
#analyzers ⇒ Object
44 |
# File 'lib/hashira/ci/baseline.rb', line 44 def analyzers = @recorded.fetch("analyzers", wanted[:analyzers]) |
#edges ⇒ Object
34 |
# File 'lib/hashira/ci/baseline.rb', line 34 def edges = @recorded.fetch("edges", []) |
#exist? ⇒ Boolean
32 |
# File 'lib/hashira/ci/baseline.rb', line 32 def exist? = File.exist?(@path) |
#findings ⇒ Object
36 |
# File 'lib/hashira/ci/baseline.rb', line 36 def findings = self.class.scored(@recorded.fetch("findings", {})) |
#findings? ⇒ Boolean
40 |
# File 'lib/hashira/ci/baseline.rb', line 40 def findings? = @recorded.key?("findings") |
#packaging ⇒ Object
42 |
# File 'lib/hashira/ci/baseline.rb', line 42 def packaging = @recorded.fetch("packaging", "folder") |
#targets ⇒ Object
46 |
# File 'lib/hashira/ci/baseline.rb', line 46 def targets = @recorded.fetch("targets", wanted[:targets]) |
#wanted ⇒ Object
48 |
# File 'lib/hashira/ci/baseline.rb', line 48 def wanted = @scope.to_h |
#write(edges, findings, packaging:) ⇒ Object
50 51 52 |
# File 'lib/hashira/ci/baseline.rb', line 50 def write(edges, findings, packaging:) File.write(@path, JSON.pretty_generate(payload(edges, findings, packaging)) << "\n") end |