Class: Ibex::Impact::Baseline
- Inherits:
-
Object
- Object
- Ibex::Impact::Baseline
- Defined in:
- lib/ibex/impact/severity.rb,
sig/ibex/impact/severity.rbs
Overview
Stores only conflict identities so a baseline is stable across state ids.
Instance Method Summary collapse
- #conflicts ⇒ Array[String]
-
#initialize(path) ⇒ Baseline
constructor
A new instance of Baseline.
- #validate_document(value) ⇒ void
- #write(identities) ⇒ void
Constructor Details
#initialize(path) ⇒ Baseline
Returns a new instance of Baseline.
12 13 14 |
# File 'lib/ibex/impact/severity.rb', line 12 def initialize(path) @path = path end |
Instance Method Details
#conflicts ⇒ Array[String]
17 18 19 20 21 22 23 24 25 26 27 28 29 30 |
# File 'lib/ibex/impact/severity.rb', line 17 def conflicts return [] unless File.file?(@path) value = JSON.parse(File.binread(@path)) validate_document(value) conflicts = value.fetch("conflicts") #: Array[untyped] unless conflicts.all? { |identity| identity.is_a?(String) && !identity.empty? } raise Ibex::Error, "#{@path}:1:1: invalid impact baseline: conflicts must contain non-empty strings" end conflicts.sort.uniq rescue JSON::ParserError => e raise Ibex::Error, "#{@path}:1:1: invalid impact baseline: #{e.}" end |
#validate_document(value) ⇒ void
This method returns an undefined value.
33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/ibex/impact/severity.rb', line 33 def validate_document(value) unless value.is_a?(Hash) && value.keys.sort == %w[conflicts schema_version] raise Ibex::Error, "#{@path}:1:1: invalid impact baseline: expected schema_version and conflicts" end unless value.fetch("conflicts").is_a?(Array) raise Ibex::Error, "#{@path}:1:1: invalid impact baseline: conflicts must be an array" end return if value.fetch("schema_version") == 1 raise Ibex::Error, "#{@path}:1:1: unsupported impact baseline schema" end |
#write(identities) ⇒ void
This method returns an undefined value.
46 47 48 |
# File 'lib/ibex/impact/severity.rb', line 46 def write(identities) File.write(@path, "#{JSON.pretty_generate({ 'schema_version' => 1, 'conflicts' => identities.sort.uniq })}\n") end |