1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47
|
# frozen_string_literal: true
# Released under the MIT License.
# Copyright, 2019-2025, by Samuel Williams.
module Console
module Event
# A generic event which can be used to represent structured data.
class Generic
# Convert the event to a hash suitable for JSON serialization.
#
# @returns [Hash] The hash representation of the event.
def to_hash
{}
end
# Convert the event to a hash suitable for JSON serialization.
#
# @returns [Hash] The hash representation of the event.
def as_json(...)
to_hash
end
# Serialize the event to JSON.
#
# @returns [String] The JSON representation of the event.
def to_json(...)
JSON.generate(as_json, ...)
end
# Convert the event to a string (JSON).
#
# @returns [String] The string representation of the event.
def to_s
to_json
end
# Log the event using the given output interface.
#
# @parameter arguments [Array] The arguments to log.
# @parameter options [Hash] Additional options to pass to the logger output.
def emit(*arguments, **options)
Console.call(*arguments, event: self, **options)
end
end
end
end
|