Class: Hashira::CI::Baseline

Inherits:
Object
  • Object
show all
Defined in:
lib/hashira/ci/baseline.rb

Constant Summary collapse

SCHEMA_VERSION =
3

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, recorded) ⇒ Baseline

Returns a new instance of Baseline.



10
11
12
13
# File 'lib/hashira/ci/baseline.rb', line 10

def initialize(path, recorded)
  @path = path
  @recorded = recorded
end

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



15
16
17
# File 'lib/hashira/ci/baseline.rb', line 15

def path
  @path
end

Class Method Details

.load(path) ⇒ Object



8
# File 'lib/hashira/ci/baseline.rb', line 8

def self.load(path) = new(path, File.exist?(path) ? JSON.parse(File.read(path)) : {})

Instance Method Details

#edgesObject



19
# File 'lib/hashira/ci/baseline.rb', line 19

def edges = @recorded.fetch("edges", [])

#exist?Boolean

Returns:

  • (Boolean)


17
# File 'lib/hashira/ci/baseline.rb', line 17

def exist? = File.exist?(@path)

#findingsObject



21
# File 'lib/hashira/ci/baseline.rb', line 21

def findings = @recorded.fetch("findings", [])

#findings?Boolean

Returns:

  • (Boolean)


23
# File 'lib/hashira/ci/baseline.rb', line 23

def findings? = @recorded.key?("findings")

#packagingObject



25
# File 'lib/hashira/ci/baseline.rb', line 25

def packaging = @recorded.fetch("packaging", "folder")

#write(edges, findings, packaging:) ⇒ Object



27
28
29
# File 'lib/hashira/ci/baseline.rb', line 27

def write(edges, findings, packaging:)
  File.write(@path, JSON.pretty_generate(payload(edges, findings, packaging)) << "\n")
end