Class: Treaty::Action::Versions::Execution::Request
- Inherits:
-
Object
- Object
- Treaty::Action::Versions::Execution::Request
- 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
- Resolve executor (constantize string if needed)
- Build call parameters (params + optional inventory)
- Execute via appropriate method:
- Proc:
executor.call(**params) - Servactory:
executor.call!(**params) - Regular:
executor.public_send(method, **params)
- Proc:
- Extract data from result (handles
.dataaccessor)
Example
result = Execution::Request.execute!(
version_factory: factory,
validated_params: { post: { title: "Hello" } },
inventory: inventory_collection,
context: controller
)
Class Method Summary collapse
-
.execute! ⇒ Hash
Executes service with validated parameters (class method shortcut).
Instance Method Summary collapse
-
#execute! ⇒ Hash
Executes the service and returns result.
-
#initialize(version_factory:, validated_params:, inventory: nil, context: nil) ⇒ Request
constructor
Creates a new execution request instance.
Constructor Details
#initialize(version_factory:, validated_params:, inventory: nil, context: nil) ⇒ Request
Creates a new execution request instance
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)
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
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 |