Module: Ibex::GenerationManifest
- Defined in:
- lib/ibex/generation_manifest.rb
Overview
Deterministic description of one published parser generation. rubocop:disable Metrics/ModuleLength -- manifest schema validation is kept in one auditable unit.
Constant Summary collapse
- SCHEMA_VERSION =
@rbs! type json_value = String | Integer | Float | bool | nil | Array | Hash[String, json_value]
1- IDENTIFIER =
: Integer
"generation"- ROOT_KEYS =
: String
%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
- .render(artifacts, source_records:, options:) ⇒ Object
-
.validate(source, verify_artifacts: true) ⇒ Object
Validate the manifest shape and, by default, every published artifact digest.
- .validate_file(path, verify_artifacts: true) ⇒ Object
Class Method Details
.render(artifacts, source_records:, options:) ⇒ Object
24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 |
# File 'lib/ibex/generation_manifest.rb', line 24 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(), "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.
42 43 44 45 46 47 48 49 50 51 |
# File 'lib/ibex/generation_manifest.rb', line 42 def validate(source, verify_artifacts: true) document = JSON.parse(source) #: Object? validate_document(document) document_hash = document #: Hash[String, json_value] artifacts = document_hash.fetch("artifacts") #: Array[Object?] verify_entries(artifacts) if verify_artifacts document_hash rescue JSON::ParserError, KeyError, TypeError, ArgumentError => e raise Ibex::Error, "(manifest):1:1: invalid generation manifest: #{e.}" end |
.validate_file(path, verify_artifacts: true) ⇒ Object
54 55 56 57 58 |
# File 'lib/ibex/generation_manifest.rb', line 54 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.}" end |