Class: Kward::Hooks::Event
- Inherits:
-
Object
- Object
- Kward::Hooks::Event
- Defined in:
- lib/kward/hooks/event.rb
Overview
Immutable lifecycle event delivered to hook handlers.
Instance Attribute Summary collapse
-
#agent ⇒ Object
readonly
Returns the value of attribute agent.
-
#frontend ⇒ Object
readonly
Returns the value of attribute frontend.
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#name ⇒ Object
readonly
Returns the value of attribute name.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#phase ⇒ Object
readonly
Returns the value of attribute phase.
-
#session ⇒ Object
readonly
Returns the value of attribute session.
-
#timestamp ⇒ Object
readonly
Returns the value of attribute timestamp.
-
#turn ⇒ Object
readonly
Returns the value of attribute turn.
-
#workspace ⇒ Object
readonly
Returns the value of attribute workspace.
Instance Method Summary collapse
- #[](key) ⇒ Object
-
#initialize(name:, phase: nil, timestamp: Time.now.utc, session: nil, turn: nil, workspace: nil, frontend: nil, agent: nil, payload: nil, id: nil) ⇒ Event
constructor
A new instance of Event.
- #to_h ⇒ Object
Constructor Details
#initialize(name:, phase: nil, timestamp: Time.now.utc, session: nil, turn: nil, workspace: nil, frontend: nil, agent: nil, payload: nil, id: nil) ⇒ Event
Returns a new instance of Event.
12 13 14 15 16 17 18 19 20 21 22 23 24 |
# File 'lib/kward/hooks/event.rb', line 12 def initialize(name:, phase: nil, timestamp: Time.now.utc, session: nil, turn: nil, workspace: nil, frontend: nil, agent: nil, payload: nil, id: nil) @id = id || "hookevt_#{SecureRandom.hex(12)}" @name = name.to_s @phase = phase&.to_s || inferred_phase(@name) @timestamp = .is_a?(Time) ? .utc : Time.parse(.to_s).utc @session = frozen_copy(session || {}) @turn = frozen_copy(turn || {}) @workspace = frozen_copy(workspace || {}) @frontend = frozen_copy(frontend || {}) @agent = frozen_copy(agent || {}) @payload = frozen_copy(payload || {}) freeze end |
Instance Attribute Details
#agent ⇒ Object (readonly)
Returns the value of attribute agent.
10 11 12 |
# File 'lib/kward/hooks/event.rb', line 10 def agent @agent end |
#frontend ⇒ Object (readonly)
Returns the value of attribute frontend.
10 11 12 |
# File 'lib/kward/hooks/event.rb', line 10 def frontend @frontend end |
#id ⇒ Object (readonly)
Returns the value of attribute id.
10 11 12 |
# File 'lib/kward/hooks/event.rb', line 10 def id @id end |
#name ⇒ Object (readonly)
Returns the value of attribute name.
10 11 12 |
# File 'lib/kward/hooks/event.rb', line 10 def name @name end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload.
10 11 12 |
# File 'lib/kward/hooks/event.rb', line 10 def payload @payload end |
#phase ⇒ Object (readonly)
Returns the value of attribute phase.
10 11 12 |
# File 'lib/kward/hooks/event.rb', line 10 def phase @phase end |
#session ⇒ Object (readonly)
Returns the value of attribute session.
10 11 12 |
# File 'lib/kward/hooks/event.rb', line 10 def session @session end |
#timestamp ⇒ Object (readonly)
Returns the value of attribute timestamp.
10 11 12 |
# File 'lib/kward/hooks/event.rb', line 10 def @timestamp end |
#turn ⇒ Object (readonly)
Returns the value of attribute turn.
10 11 12 |
# File 'lib/kward/hooks/event.rb', line 10 def turn @turn end |
#workspace ⇒ Object (readonly)
Returns the value of attribute workspace.
10 11 12 |
# File 'lib/kward/hooks/event.rb', line 10 def workspace @workspace end |
Instance Method Details
#[](key) ⇒ Object
26 27 28 |
# File 'lib/kward/hooks/event.rb', line 26 def [](key) payload[key] || payload[key.to_s] end |
#to_h ⇒ Object
30 31 32 33 34 35 36 37 38 39 40 41 42 43 |
# File 'lib/kward/hooks/event.rb', line 30 def to_h { id: id, name: name, phase: phase, timestamp: .iso8601, session: session, turn: turn, workspace: workspace, frontend: frontend, agent: agent, payload: payload } end |