Class: Ask::SessionProtocol::Interactions::Interaction
- Inherits:
-
Data
- Object
- Data
- Ask::SessionProtocol::Interactions::Interaction
- Defined in:
- lib/ask/session_protocol/interactions.rb
Overview
An interaction on the wire. Immutable.
{ "id" => "act_123", "kind" => "approval",
"status" => "pending", "payload" => { "toolName" => "bash", ... } }
Instance Attribute Summary collapse
-
#id ⇒ Object
readonly
Returns the value of attribute id.
-
#kind ⇒ Object
readonly
Returns the value of attribute kind.
-
#payload ⇒ Object
readonly
Returns the value of attribute payload.
-
#status ⇒ Object
readonly
Returns the value of attribute status.
Instance Method Summary collapse
-
#initialize(id:, kind:, status: "pending", payload: {}) ⇒ Interaction
constructor
A new instance of Interaction.
- #pending? ⇒ Boolean
- #resolved? ⇒ Boolean
- #to_h ⇒ Object
Constructor Details
#initialize(id:, kind:, status: "pending", payload: {}) ⇒ Interaction
Returns a new instance of Interaction.
29 30 31 32 33 34 35 36 37 38 39 40 41 42 |
# File 'lib/ask/session_protocol/interactions.rb', line 29 def initialize(id:, kind:, status: "pending", payload: {}) unless id.is_a?(String) && !id.empty? raise ArgumentError, "interaction id must be a non-empty String" end unless KINDS.include?(kind) raise ArgumentError, "unknown interaction kind: #{kind.inspect} (expected one of #{KINDS.inspect})" end unless STATUSES.include?(status) raise ArgumentError, "unknown interaction status: #{status.inspect} (expected one of #{STATUSES.inspect})" end raise ArgumentError, "interaction payload must be a Hash" unless payload.is_a?(Hash) super end |
Instance Attribute Details
#id ⇒ Object (readonly)
Returns the value of attribute id
28 29 30 |
# File 'lib/ask/session_protocol/interactions.rb', line 28 def id @id end |
#kind ⇒ Object (readonly)
Returns the value of attribute kind
28 29 30 |
# File 'lib/ask/session_protocol/interactions.rb', line 28 def kind @kind end |
#payload ⇒ Object (readonly)
Returns the value of attribute payload
28 29 30 |
# File 'lib/ask/session_protocol/interactions.rb', line 28 def payload @payload end |
#status ⇒ Object (readonly)
Returns the value of attribute status
28 29 30 |
# File 'lib/ask/session_protocol/interactions.rb', line 28 def status @status end |
Instance Method Details
#pending? ⇒ Boolean
44 45 46 |
# File 'lib/ask/session_protocol/interactions.rb', line 44 def pending? status == "pending" end |
#resolved? ⇒ Boolean
48 49 50 |
# File 'lib/ask/session_protocol/interactions.rb', line 48 def resolved? status != "pending" end |
#to_h ⇒ Object
52 53 54 |
# File 'lib/ask/session_protocol/interactions.rb', line 52 def to_h { "id" => id, "kind" => kind, "status" => status, "payload" => payload } end |