Class: Console::Event::Generic

Inherits:
Object
  • Object
show all
Defined in:
lib/console/event/generic.rb

Overview

A generic event which can be used to represent structured data.

Direct Known Subclasses

Failure, Spawn

Instance Method Summary collapse

Instance Method Details

#as_jsonObject

Convert the event to a hash suitable for JSON serialization.



20
21
22
# File 'lib/console/event/generic.rb', line 20

def as_json(...)
  to_hash
end

#emit(*arguments, **options) ⇒ Object

Log the event using the given output interface.



42
43
44
# File 'lib/console/event/generic.rb', line 42

def emit(*arguments, **options)
  Console.call(*arguments, event: self, **options)
end

#to_hashObject

Convert the event to a hash suitable for JSON serialization.



13
14
15
# File 'lib/console/event/generic.rb', line 13

def to_hash
  {}
end

#to_jsonObject

Serialize the event to JSON.



27
28
29
# File 'lib/console/event/generic.rb', line 27

def to_json(...)
  JSON.generate(as_json, ...)
end

#to_sObject

Convert the event to a string (JSON).



34
35
36
# File 'lib/console/event/generic.rb', line 34

def to_s
  to_json
end