Module: Igniter::Contracts::Execution::StepResultRuntime
- Defined in:
- lib/igniter/contracts/execution/step_result_runtime.rb
Class Method Summary collapse
- .failed_step_dependency(operation, state:) ⇒ Object
- .halted_dependency_result(operation, dependency) ⇒ Object
- .handle_step(operation:, state:) ⇒ Object
- .normalize_step_result(value) ⇒ Object
- .step_dependency_values(operation, state:) ⇒ Object
Class Method Details
.failed_step_dependency(operation, state:) ⇒ Object
17 18 19 20 21 22 23 24 |
# File 'lib/igniter/contracts/execution/step_result_runtime.rb', line 17 def failed_step_dependency(operation, state:) Array(operation.attributes[:depends_on]).filter_map do |dependency| dependency_name = dependency.to_sym value = state.fetch(dependency_name) { name: dependency_name, result: value } if value.is_a?(StepResult) && value.failure? end.first end |
.halted_dependency_result(operation, dependency) ⇒ Object
26 27 28 29 30 31 32 33 34 35 |
# File 'lib/igniter/contracts/execution/step_result_runtime.rb', line 26 def halted_dependency_result(operation, dependency) StepResult.failure( code: :halted_dependency, message: "step #{operation.name} halted because dependency #{dependency.fetch(:name)} failed", details: { dependency: dependency.fetch(:name), failure: dependency.fetch(:result).failure } ) end |
.handle_step(operation:, state:) ⇒ Object
9 10 11 12 13 14 15 |
# File 'lib/igniter/contracts/execution/step_result_runtime.rb', line 9 def handle_step(operation:, state:, **) failed_dependency = failed_step_dependency(operation, state: state) return halted_dependency_result(operation, failed_dependency) if failed_dependency callable = operation.attributes[:callable] normalize_step_result(callable.call(**step_dependency_values(operation, state: state))) end |
.normalize_step_result(value) ⇒ Object
45 46 47 |
# File 'lib/igniter/contracts/execution/step_result_runtime.rb', line 45 def normalize_step_result(value) value.is_a?(StepResult) ? value : StepResult.success(value) end |
.step_dependency_values(operation, state:) ⇒ Object
37 38 39 40 41 42 43 |
# File 'lib/igniter/contracts/execution/step_result_runtime.rb', line 37 def step_dependency_values(operation, state:) Array(operation.attributes[:depends_on]).each_with_object({}) do |dependency, memo| dependency_name = dependency.to_sym value = state.fetch(dependency_name) memo[dependency_name] = value.is_a?(StepResult) ? value.value : value end end |