Module: Ibex::Coverage::RuntimeEventValidator

Defined in:
lib/ibex/coverage/runtime_event_validator.rb,
sig/ibex/coverage/runtime_event_validator.rbs

Overview

Dependency-free structural validation for runtime-event schema version 1.

Constant Summary collapse

TOKEN_KEYS =

RBS:

  • type json_value = String | Integer | Float | bool | nil | Array[json_value] | Hash[String, json_value]

Returns:

  • (Array[String])
%w[location state token token_id value].freeze
LOCATION_KEYS =

Signature:

  • Array[String]

Returns:

  • (Array[String])
%w[column end_column end_line file line].freeze
VALIDATORS =

Signature:

  • Array[String]

Returns:

  • (Hash[String, Symbol])
{
  "start" => :valid_start?,
  "shift" => :valid_shift?,
  "reduce" => :valid_reduce?,
  "error" => :valid_error?,
  "recover" => :valid_recover?,
  "discard" => :valid_discard?,
  "accept" => :valid_accept?,
  "reject" => :valid_reject?
}.freeze

Class Method Summary collapse

Class Method Details

.valid?(document) ⇒ Boolean

RBS:

  • (Hash[String, json_value] document) -> bool

Parameters:

  • document (Hash[String, json_value])

Returns:

  • (Boolean)


26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/ibex/coverage/runtime_event_validator.rb', line 26

def valid?(document)
  data = document["data"]
  return false unless data.is_a?(Hash) && data.keys.all?(String)

  event_data = data #: Hash[String, json_value]

  event = document["event"]
  return false unless event.is_a?(String)

  validator = VALIDATORS[event]
  validator ? send(validator, event_data) : false
end