Class: Events::Base Abstract
- Inherits:
-
Object
- Object
- Events::Base
- Defined in:
- lib/events/base.rb
Overview
Subclass and implement #type
Base class for all Anima events. Subclasses must implement #type returning a string identifier (e.g. “user_message”).
Events are POROs — they carry typed payloads through the event bus. Persistence is a separate concern handled by ActiveRecord models.
Direct Known Subclasses
AgentMessage, BounceBack, SystemMessage, ToolCall, ToolResponse, UserMessage
Instance Attribute Summary collapse
-
#content ⇒ Object
readonly
Returns the value of attribute content.
-
#session_id ⇒ Object
readonly
Returns the value of attribute session_id.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
Instance Method Summary collapse
-
#event_name ⇒ String
Namespaced event name for Rails.event (e.g. “anima.user_message”).
-
#initialize(content:, session_id: nil) ⇒ Base
constructor
A new instance of Base.
-
#to_h ⇒ Hash
Serialized event payload.
-
#type ⇒ String
Event type identifier.
Constructor Details
#initialize(content:, session_id: nil) ⇒ Base
Returns a new instance of Base.
16 17 18 19 20 |
# File 'lib/events/base.rb', line 16 def initialize(content:, session_id: nil) @content = content @session_id = session_id @timestamp = Process.clock_gettime(Process::CLOCK_REALTIME, :nanosecond) end |
Instance Attribute Details
#content ⇒ Object (readonly)
Returns the value of attribute content.
12 13 14 |
# File 'lib/events/base.rb', line 12 def content @content end |
#session_id ⇒ Object (readonly)
Returns the value of attribute session_id.
12 13 14 |
# File 'lib/events/base.rb', line 12 def session_id @session_id end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
12 13 14 |
# File 'lib/events/base.rb', line 12 def @timestamp end |
Instance Method Details
#event_name ⇒ String
Returns namespaced event name for Rails.event (e.g. “anima.user_message”).
29 30 31 |
# File 'lib/events/base.rb', line 29 def event_name "#{Bus::NAMESPACE}.#{type}" end |
#to_h ⇒ Hash
Returns serialized event payload.
34 35 36 |
# File 'lib/events/base.rb', line 34 def to_h {type: type, content: content, session_id: session_id, timestamp: } end |
#type ⇒ String
Returns event type identifier.
24 25 26 |
# File 'lib/events/base.rb', line 24 def type raise NotImplementedError, "#{self.class} must implement #type" end |