Module: Ibex::Coverage::RuntimeEventValidator

Defined in:
lib/ibex/coverage/runtime_event_validator.rb

Overview

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

Constant Summary collapse

TOKEN_KEYS =

: Array

%w[location state token token_id value].freeze
LOCATION_KEYS =

: Array

%w[column end_column end_line file line].freeze
VALIDATORS =
{
  "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

Returns:

  • (Boolean)


23
24
25
26
27
28
29
# File 'lib/ibex/coverage/runtime_event_validator.rb', line 23

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

  validator = VALIDATORS[document["event"]]
  validator ? send(validator, data) : false
end