Sha256: 73fb25d77e5e1e71d87b3b7975fa1739eaea114cd01c8d974ca719413d9faae2

Contents?: true

Size: 1.62 KB

Versions: 19

Compression:

Stored size: 1.62 KB

Contents

# frozen_string_literal: true

module Opera
  module Operation
    module Instructions
      module Executors
        class Operations < Executor
          class WrongOperationsResultError < Opera::Error; end

          # rubocop:disable Metrics/MethodLength
          def call(instruction)
            instruction[:kind] = :step
            operations_results = super

            return if result.exceptions.any?

            case operations_results
            when Array
              operations_results.each do |operation_result|
                raise_error unless operation_result.is_a?(Opera::Operation::Result)
              end

              failures = operations_results.select(&:failure?)

              if failures.any?
                add_failures(failures)
              else
                add_results(instruction, operations_results)
              end
            else
              raise_error
            end
          end
          # rubocop:enable Metrics/MethodLength

          private

          def add_failures(failures)
            failures.each do |failure|
              result.add_errors(failure.errors)
              result.add_exceptions(failure.exceptions)
            end
          end

          def add_results(instruction, results)
            add_instruction_output(instruction, results.map(&:output))
            execution = result.executions.pop
            result.executions << { execution => results.map(&:executions) }
          end

          def raise_error
            raise WrongOperationsResultError, 'Have to return array of Opera::Operation::Result'
          end
        end
      end
    end
  end
end

Version data entries

19 entries across 19 versions & 1 rubygems

Version Path
opera-0.2.15 lib/opera/operation/instructions/executors/operations.rb
opera-0.2.14 lib/opera/operation/instructions/executors/operations.rb
opera-0.2.13 lib/opera/operation/instructions/executors/operations.rb
opera-0.2.12 lib/opera/operation/instructions/executors/operations.rb
opera-0.2.11 lib/opera/operation/instructions/executors/operations.rb
opera-0.2.10 lib/opera/operation/instructions/executors/operations.rb
opera-0.2.9 lib/opera/operation/instructions/executors/operations.rb
opera-0.2.8 lib/opera/operation/instructions/executors/operations.rb
opera-0.2.7 lib/opera/operation/instructions/executors/operations.rb
opera-0.2.6 lib/opera/operation/instructions/executors/operations.rb
opera-0.2.5 lib/opera/operation/instructions/executors/operations.rb
opera-0.2.4 lib/opera/operation/instructions/executors/operations.rb
opera-0.2.3 lib/opera/operation/instructions/executors/operations.rb
opera-0.2.2 lib/opera/operation/instructions/executors/operations.rb
opera-0.2.1 lib/opera/operation/instructions/executors/operations.rb
opera-0.2.0 lib/opera/operation/instructions/executors/operations.rb
opera-0.1.2 lib/opera/operation/instructions/executors/operations.rb
opera-0.1.1 lib/opera/operation/instructions/executors/operations.rb
opera-0.1.0 lib/opera/operation/instructions/executors/operations.rb