Sha256: 32e1356c6372ba70c93e30711a7dc18c590a3a09eaf697e123e1b87e250a638b

Contents?: true

Size: 1.14 KB

Versions: 7

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.to_h)

              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

7 entries across 7 versions & 1 rubygems

Version Path
opera-0.2.17 lib/opera/operation/instructions/executors/validate.rb
opera-0.2.16 lib/opera/operation/instructions/executors/validate.rb
opera-0.2.15 lib/opera/operation/instructions/executors/validate.rb
opera-0.2.14 lib/opera/operation/instructions/executors/validate.rb
opera-0.2.13 lib/opera/operation/instructions/executors/validate.rb
opera-0.2.12 lib/opera/operation/instructions/executors/validate.rb
opera-0.2.11 lib/opera/operation/instructions/executors/validate.rb