Module: Ibex::GenerationManifest

Defined in:
lib/ibex/generation_manifest.rb

Overview

Deterministic description of one published parser generation.

Constant Summary collapse

SCHEMA_VERSION =

: Integer

1
IDENTIFIER =

: String

"generation"
ROOT_KEYS =

: Array

%w[ibex_manifest schema_version input options artifacts].freeze
INPUT_KEYS =

: Array

%w[root sha256 files].freeze
FILE_KEYS =

: Array

%w[path sha256 bytesize].freeze
ARTIFACT_KEYS =

: Array

%w[kind path sha256 bytesize].freeze

Class Method Summary collapse

Class Method Details

.render(artifacts, source_records:, options:) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
# File 'lib/ibex/generation_manifest.rb', line 20

def render(artifacts, source_records:, options:)
  files = source_records.map(&:to_h)
  document = {
    "ibex_manifest" => IDENTIFIER,
    "schema_version" => SCHEMA_VERSION,
    "input" => {
      "root" => files.fetch(0).fetch("path"),
      "sha256" => input_digest(files),
      "files" => files
    },
    "options" => sorted_hash(options),
    "artifacts" => artifacts.map { |artifact| artifact_entry(artifact) }
  }
  "#{JSON.pretty_generate(document)}\n"
end

.validate(source, verify_artifacts: true) ⇒ Object

Validate the manifest shape and, by default, every published artifact digest.



38
39
40
41
42
43
44
45
# File 'lib/ibex/generation_manifest.rb', line 38

def validate(source, verify_artifacts: true)
  document = JSON.parse(source)
  validate_document(document)
  verify_entries(document.fetch("artifacts")) if verify_artifacts
  document
rescue JSON::ParserError, KeyError, TypeError, ArgumentError => e
  raise Ibex::Error, "(manifest):1:1: invalid generation manifest: #{e.message}"
end

.validate_file(path, verify_artifacts: true) ⇒ Object



48
49
50
51
52
# File 'lib/ibex/generation_manifest.rb', line 48

def validate_file(path, verify_artifacts: true)
  validate(File.binread(path), verify_artifacts: verify_artifacts)
rescue SystemCallError, ArgumentError => e
  raise Ibex::Error, "#{path}:1:1: cannot read generation manifest: #{e.message}"
end