Sha256: 61601367d997821be746b05dfd0e9421ebfaff59f7284777e5b80a6126a8cd5a

Contents?: true

Size: 1.14 KB

Versions: 5

Compression:

Stored size: 1.14 KB

Contents

# frozen_string_literal: true

module Opera
  module Operation
    module Instructions
      module Executors
        class Validate < Executor
          def break_condition
            operation.finished?
          end

          private

          def evaluate_instruction(instruction)
            instruction[:kind] = :step
            dry_result = super

            case dry_result
            when Opera::Operation::Result
              add_instruction_output(instruction, dry_result.output)

              unless dry_result.success?
                result.add_errors(dry_result.errors)
                result.add_exceptions(dry_result.exceptions)
              end
            when Dry::Validation::Result
              add_instruction_output(instruction, dry_result.to_h)

              result.add_errors(dry_result.errors) unless dry_result.success?
            else
              exception_message = "#{dry_result.class} is not expected object. Please check: #{dry_result.inspect}"
              result.add_exception(instruction[:method], exception_message, classname: operation.class.name)
            end
          end
        end
      end
    end
  end
end

Version data entries

5 entries across 5 versions & 1 rubygems

Version Path
opera-0.3.3 lib/opera/operation/instructions/executors/validate.rb
opera-0.3.2 lib/opera/operation/instructions/executors/validate.rb
opera-0.3.1 lib/opera/operation/instructions/executors/validate.rb
opera-0.3.0 lib/opera/operation/instructions/executors/validate.rb
opera-0.2.18 lib/opera/operation/instructions/executors/validate.rb