Skip to content
Kward Search API index

Class: Kward::Hooks::Event

Inherits:
Object
  • Object
show all
Defined in:
lib/kward/hooks/event.rb

Overview

Immutable lifecycle event delivered to hook handlers.

Instance Attribute Summary collapse

Instance Method Summary collapse

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 = timestamp.is_a?(Time) ? timestamp.utc : Time.parse(timestamp.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

#agentObject (readonly)

Returns the value of attribute agent.



10
11
12
# File 'lib/kward/hooks/event.rb', line 10

def agent
  @agent
end

#frontendObject (readonly)

Returns the value of attribute frontend.



10
11
12
# File 'lib/kward/hooks/event.rb', line 10

def frontend
  @frontend
end

#idObject (readonly)

Returns the value of attribute id.



10
11
12
# File 'lib/kward/hooks/event.rb', line 10

def id
  @id
end

#nameObject (readonly)

Returns the value of attribute name.



10
11
12
# File 'lib/kward/hooks/event.rb', line 10

def name
  @name
end

#payloadObject (readonly)

Returns the value of attribute payload.



10
11
12
# File 'lib/kward/hooks/event.rb', line 10

def payload
  @payload
end

#phaseObject (readonly)

Returns the value of attribute phase.



10
11
12
# File 'lib/kward/hooks/event.rb', line 10

def phase
  @phase
end

#sessionObject (readonly)

Returns the value of attribute session.



10
11
12
# File 'lib/kward/hooks/event.rb', line 10

def session
  @session
end

#timestampObject (readonly)

Returns the value of attribute timestamp.



10
11
12
# File 'lib/kward/hooks/event.rb', line 10

def timestamp
  @timestamp
end

#turnObject (readonly)

Returns the value of attribute turn.



10
11
12
# File 'lib/kward/hooks/event.rb', line 10

def turn
  @turn
end

#workspaceObject (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_hObject



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: timestamp.iso8601,
    session: session,
    turn: turn,
    workspace: workspace,
    frontend: frontend,
    agent: agent,
    payload: payload
  }
end