Class: Treaty::Action::Result

Inherits:
Object
  • Object
show all
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

Instance Method Summary collapse

Constructor Details

#initialize(data:, status:, version:) ⇒ Result

Creates a new result instance

Parameters:

  • data (Hash)

    Validated response data

  • status (Integer)

    HTTP status code

  • version (Gem::Version)

    Resolved version



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

#dataHash (readonly)

Returns Validated response data.

Returns:

  • (Hash)

    Validated response data



45
46
47
# File 'lib/treaty/action/result.rb', line 45

def data
  @data
end

#statusInteger (readonly)

Returns HTTP status code.

Returns:

  • (Integer)

    HTTP status code



48
49
50
# File 'lib/treaty/action/result.rb', line 48

def status
  @status
end

#versionGem::Version (readonly)

Returns Resolved API version.

Returns:

  • (Gem::Version)

    Resolved API version



51
52
53
# File 'lib/treaty/action/result.rb', line 51

def version
  @version
end

Instance Method Details

#inspectString

Returns human-readable representation for debugging

Returns:

  • (String)

    Inspection string with all attributes



67
68
69
# File 'lib/treaty/action/result.rb', line 67

def inspect
  "#<#{self.class.name} #{draw_result}>"
end