Class: Ibex::TableArtifact::Validator
- Inherits:
-
Object
- Object
- Ibex::TableArtifact::Validator
- Includes:
- ValidationSupport
- Defined in:
- lib/ibex/table_artifact/validator.rb
Overview
Closed structural and referential validation for untrusted sidecars.
Constant Summary collapse
- ROOT_KEYS =
: Array
%w[artifact_type schema_version identity payload cost].freeze
- PAYLOAD_KEYS =
%w[ table_format source state_count symbols tokens entry_states tables productions cst recovery semantic_actions ].freeze
Constants included from ValidationSupport
Ibex::TableArtifact::ValidationSupport::DIGEST
Class Method Summary collapse
Instance Method Summary collapse
-
#initialize(data) ⇒ Validator
constructor
A new instance of Validator.
-
#validate! ⇒ Object
rubocop:disable Naming/PredicateMethod -- bang denotes fail-fast validation.
Constructor Details
#initialize(data) ⇒ Validator
Returns a new instance of Validator.
26 27 28 |
# File 'lib/ibex/table_artifact/validator.rb', line 26 def initialize(data) @data = data end |
Class Method Details
.validate!(data) ⇒ Object
20 21 22 |
# File 'lib/ibex/table_artifact/validator.rb', line 20 def validate!(data) new(data).validate! end |
Instance Method Details
#validate! ⇒ Object
rubocop:disable Naming/PredicateMethod -- bang denotes fail-fast validation.
32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 |
# File 'lib/ibex/table_artifact/validator.rb', line 32 def validate! record(@data, "$", ROOT_KEYS) payload = record(@data.fetch("payload"), "$.payload", PAYLOAD_KEYS) validate_root_identity representation = validate_table_format(payload.fetch("table_format")) validate_source(payload.fetch("source")) state_count = integer(payload.fetch("state_count"), "$.payload.state_count", minimum: 1) symbols = validate_symbols(payload.fetch("symbols")) validate_tokens(payload.fetch("tokens"), symbols) validate_entries(payload.fetch("entry_states"), symbols, state_count) productions = validate_productions(payload.fetch("productions"), symbols) tables = payload.fetch("tables") #: Hash[String, ValidationSupport::json_value] TableValidator.new( tables, state_count: state_count, production_count: productions.length, terminal_ids: symbol_ids(symbols, "terminal"), nonterminal_ids: symbol_ids(symbols, "nonterminal"), representation: representation ).validate! MetadataValidator.new(payload, symbols: symbols, productions: productions).validate! validate_cost(@data.fetch("cost"), payload) true end |