Class: Hashira::CI::Baseline

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

Constant Summary collapse

SCHEMA_VERSION =
2

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, recorded) ⇒ Baseline

Returns a new instance of Baseline.



12
13
14
15
# File 'lib/hashira/ci/baseline.rb', line 12

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

Instance Attribute Details

#pathObject (readonly)

Returns the value of attribute path.



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

def path
  @path
end

Class Method Details

.load(path) ⇒ Object



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

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

Instance Method Details

#edgesObject



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

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

#exist?Boolean

Returns:

  • (Boolean)


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

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

#findingsObject



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

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

#ratchets_findings?Boolean

Returns:

  • (Boolean)


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

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

#write(edges, findings) ⇒ Object



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

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