Class: Ibex::Runtime::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/ibex/runtime/event.rb,
sig/ibex/runtime/event.rbs

Overview

One immutable versioned parser observation.

Constant Summary collapse

SCHEMA_VERSION =

RBS:

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

Returns:

  • (Integer)
1
IDENTIFIER =

Signature:

  • Integer

Returns:

  • (String)
"runtime-event"
TYPES =

Signature:

  • String

Returns:

  • (Array[Symbol])
%i[
  start shift reduce error recover discard accept reject cst_built cst_fallback cst_reuse
].freeze

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(type:, sequence:, data:) ⇒ Event

Returns a new instance of Event.

RBS:

  • (type: Symbol, sequence: Integer, data: Hash[Object?, Object?]) -> void

Parameters:

  • type: (Symbol)
  • sequence: (Integer)
  • data: (Hash[Object?, Object?])


24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
# File 'lib/ibex/runtime/event.rb', line 24

def initialize(type:, sequence:, data:)
  raise ArgumentError, "unknown runtime event type #{type.inspect}" unless TYPES.include?(type)
  raise ArgumentError, "runtime event sequence must be positive" unless sequence.positive?

  @type = type
  @sequence = sequence
  @data = EventSanitizer.data(data)
  @document = {
    "ibex_runtime_event" => IDENTIFIER,
    "schema_version" => SCHEMA_VERSION,
    "sequence" => @sequence,
    "event" => @type.to_s.freeze,
    "data" => @data
  }.freeze #: Hash[String, json_value]
  freeze
end

Instance Attribute Details

#dataHash[String, json_value] (readonly)

Signature:

  • Hash[String, json_value]

Returns:

  • (Hash[String, json_value])


21
22
23
# File 'lib/ibex/runtime/event.rb', line 21

def data
  @data
end

#sequenceInteger (readonly)

Signature:

  • Integer

Returns:

  • (Integer)


20
21
22
# File 'lib/ibex/runtime/event.rb', line 20

def sequence
  @sequence
end

#typeSymbol (readonly)

Signature:

  • Array[Symbol]

Returns:

  • (Symbol)


19
20
21
# File 'lib/ibex/runtime/event.rb', line 19

def type
  @type
end

Instance Method Details

#to_hHash[String, json_value]

RBS:

  • () -> Hash[String, json_value]

Returns:

  • (Hash[String, json_value])


42
43
44
# File 'lib/ibex/runtime/event.rb', line 42

def to_h
  @document
end