struct
Sepia::LogEvent
- Sepia::LogEvent
- Struct
- Value
- Object
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
- timestamp: When the event occurred
- event_type: Type of operation (Created, Updated, Deleted)
- generation: Object generation number for optimistic concurrency
- metadata: Optional user-provided context (username, reason, etc.)
Example
event = Sepia::LogEvent.new(
event_type: Sepia::LogEventType::Updated,
generation: 2,
metadata: {"user" => "alice", "reason" => "content_edit"}
)
Defined in:
sepia/event.crConstructors
-
.activity(metadata = nil) : self
Creates a LogEvent for user activities.
-
.created(generation : Int32, metadata = nil) : self
Creates a LogEvent for object creation.
-
.deleted(metadata = nil) : self
Creates a LogEvent for object deletion.
-
.from_json(json_string : String) : self
Creates a LogEvent from JSON string.
- .new(event_type : LogEventType, generation : Int32, metadata : JSON::Any = JSON::Any.new({} of String => JSON::Any), timestamp : Time = Time.local)
-
.updated(generation : Int32, metadata = nil) : self
Creates a LogEvent for object updates.
Instance Method Summary
- #event_type : LogEventType
- #event_type=(event_type : LogEventType)
- #generation : Int32
- #generation=(generation : Int32)
- #metadata : JSON::Any
- #metadata=(metadata : JSON::Any)
- #timestamp : Time
- #timestamp=(timestamp : Time)
-
#to_json(json : JSON::Builder)
Serializes the event to JSON format (builder version).
-
#to_json : String
Serializes the event to JSON format.
Constructor Detail
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"})
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"})
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"})
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)
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"})
Instance Method Detail
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
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"}}