Class: Treaty::Action::Versions::Execution::Request

Inherits:
Object
  • Object
show all
Defined in:
lib/treaty/action/versions/execution/request.rb

Overview

Executes the configured service/proc with validated parameters.

Purpose

Handles the actual execution of the delegated service, supporting multiple executor types: Class, String path, and Proc/Lambda. Provides special handling for Servactory services.

Usage

Called by:

  • Versions::Workspace (after request validation)

Executor Types

Type Example Resolution
Class Posts::CreateService Direct call
String "posts/create_service" Constantized then called
Proc ->(params:) { ... } Direct call

Servactory Integration

Detects Servactory services via servactory? class method. Catches Servactory-specific exceptions and wraps them in Treaty::Exceptions::Execution.

Execution Flow

  1. Resolve executor (constantize string if needed)
  2. Build call parameters (params + optional inventory)
  3. Execute via appropriate method:
    • Proc: executor.call(**params)
    • Servactory: executor.call!(**params)
    • Regular: executor.public_send(method, **params)
  4. Extract data from result (handles .data accessor)

Example

result = Execution::Request.execute!(
version_factory: factory,
validated_params: { post: { title: "Hello" } },
inventory: inventory_collection,
context: controller
)

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(version_factory:, validated_params:, inventory: nil, context: nil) ⇒ Request

Creates a new execution request instance

Parameters:



71
72
73
74
75
76
# File 'lib/treaty/action/versions/execution/request.rb', line 71

def initialize(version_factory:, validated_params:, inventory: nil, context: nil)
  @inventory = inventory
  @context = context
  @version_factory = version_factory
  @validated_params = validated_params
end

Class Method Details

.execute!Hash

Executes service with validated parameters (class method shortcut)

Parameters:

Returns:

  • (Hash)

    Service execution result

Raises:



61
62
63
# File 'lib/treaty/action/versions/execution/request.rb', line 61

def self.execute!(...)
  new(...).execute!
end

Instance Method Details

#execute!Hash

Executes the service and returns result

Returns:

  • (Hash)

    Execution result data

Raises:



82
83
84
85
86
# File 'lib/treaty/action/versions/execution/request.rb', line 82

def execute!
  raise_executor_missing_error! if @version_factory.executor.nil?

  extract_data_from_result
end