struct Sepia::LogEvent

Overview

Represents an event in the Sepia object lifecycle.

This struct captures when and how an object was modified, including optional metadata provided during save operations.

Properties

Example

event = Sepia::LogEvent.new(
  event_type: Sepia::LogEventType::Updated,
  generation: 2,
  metadata: {"user" => "alice", "reason" => "content_edit"}
)

Defined in:

sepia/event.cr

Constructors

Instance Method Summary

Constructor Detail

def self.activity(metadata = nil) : self #

Creates a LogEvent for user activities.

Parameters

  • metadata : Optional metadata for the activity event

Returns

A new LogEvent with Activity type (generation is always 0 for activities)

Example

event = Sepia::LogEvent.activity({"action" => "moved_lane", "user" => "alice"})

[View source]
def self.created(generation : Int32, metadata = nil) : self #

Creates a LogEvent for object creation.

Parameters

  • generation : Initial generation number (usually 1)
  • metadata : Optional metadata for the creation event

Returns

A new LogEvent with Created type

Example

event = Sepia::LogEvent.created(1, {"user" => "alice"})

[View source]
def self.deleted(metadata = nil) : self #

Creates a LogEvent for object deletion.

Parameters

  • metadata : Optional metadata for the deletion event

Returns

A new LogEvent with Deleted type (generation is always 0 for deletions)

Example

event = Sepia::LogEvent.deleted({"user" => "admin", "reason" => "cleanup"})

[View source]
def self.from_json(json_string : String) : self #

Creates a LogEvent from JSON string.

Parameters

  • json_string : JSON representation of the event

Returns

A new LogEvent instance parsed from the JSON

Example

event_json = %({"ts":"2025-01-15T10:30:45Z","type":"updated","gen":2,"meta":{"user":"alice"}})
event = Sepia::LogEvent.from_json(event_json)

[View source]
def self.new(event_type : LogEventType, generation : Int32, metadata : JSON::Any = JSON::Any.new({} of String => JSON::Any), timestamp : Time = Time.local) #

[View source]
def self.updated(generation : Int32, metadata = nil) : self #

Creates a LogEvent for object updates.

Parameters

  • generation : New generation number after update
  • metadata : Optional metadata for the update event

Returns

A new LogEvent with Updated type

Example

event = Sepia::LogEvent.updated(2, {"user" => "bob", "reason" => "fix_typo"})

[View source]

Instance Method Detail

def event_type : LogEventType #

[View source]
def event_type=(event_type : LogEventType) #

[View source]
def generation : Int32 #

[View source]
def generation=(generation : Int32) #

[View source]
def metadata : JSON::Any #

[View source]
def metadata=(metadata : JSON::Any) #

[View source]
def timestamp : Time #

[View source]
def timestamp=(timestamp : Time) #

[View source]
def to_json(json : JSON::Builder) #

Serializes the event to JSON format (builder version).

This method writes the JSON representation to the provided JSON::Builder. Used internally by the JSON serialization system.

Parameters

  • json : JSON::Builder to write to

[View source]
def to_json : String #

Serializes the event to JSON format.

Returns

A JSON string representation of the event

Example

event = Sepia::LogEvent.new(Sepia::LogEventType::Created, 1, {"user" => "alice"})
json = event.to_json # => {"ts":"2025-01-15T10:30:45Z","type":"created","gen":1,"meta":{"user":"alice"}}

[View source]