Class: Treaty::Action::Result
- Inherits:
-
Object
- Object
- Treaty::Action::Result
- Defined in:
- lib/treaty/action/result.rb
Overview
Value object returned from treaty execution.
Purpose
Encapsulates the result of a treaty call, containing validated
response data, HTTP status code, and resolved version. This is
the primary return type from Treaty.call!.
Usage
Created by:
- Versions::Workspace (at the end of treaty execution)
Consumed by:
- Controller::DSL (to render JSON response)
- Test assertions (to verify treaty behavior)
Attributes
| Attribute | Description |
|---|---|
data |
Validated and transformed response hash |
status |
HTTP status code from response definition |
version |
Resolved Gem::Version object |
Example
result = Posts::CreateTreaty.call!(
version: "1",
params: { post: { title: "Hello" } }
)
result.data # => { post: { id: "abc", title: "Hello" } }
result.status # => 201
result.version # => Gem::Version.new("1")
# In controller:
render json: result.data, status: result.status
Instance Attribute Summary collapse
-
#data ⇒ Hash
readonly
Validated response data.
-
#status ⇒ Integer
readonly
HTTP status code.
-
#version ⇒ Gem::Version
readonly
Resolved API version.
Instance Method Summary collapse
-
#initialize(data:, status:, version:) ⇒ Result
constructor
Creates a new result instance.
-
#inspect ⇒ String
Returns human-readable representation for debugging.
Constructor Details
#initialize(data:, status:, version:) ⇒ Result
Creates a new result instance
58 59 60 61 62 |
# File 'lib/treaty/action/result.rb', line 58 def initialize(data:, status:, version:) @data = data @status = status @version = version end |
Instance Attribute Details
#data ⇒ Hash (readonly)
Returns Validated response data.
45 46 47 |
# File 'lib/treaty/action/result.rb', line 45 def data @data end |
#status ⇒ Integer (readonly)
Returns HTTP status code.
48 49 50 |
# File 'lib/treaty/action/result.rb', line 48 def status @status end |
#version ⇒ Gem::Version (readonly)
Returns Resolved API version.
51 52 53 |
# File 'lib/treaty/action/result.rb', line 51 def version @version end |
Instance Method Details
#inspect ⇒ String
Returns human-readable representation for debugging
67 68 69 |
# File 'lib/treaty/action/result.rb', line 67 def inspect "#<#{self.class.name} #{draw_result}>" end |