Class: UseCase::Validator

Inherits:
ValidatorParent show all
Includes:
UseCaseValidations
Defined in:
lib/usecasing/validator.rb

Constant Summary

Constants included from UseCaseValidations

UseCaseValidations::VERSION

Instance Method Summary collapse

Methods included from UseCaseValidations

included

Methods inherited from ValidatorParent

#call_failure

Instance Method Details

#performObject



7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
# File 'lib/usecasing/validator.rb', line 7

def perform
  targets = [*target]

  if target.nil?
    all_validations_green = false

  elsif targets.empty?
    all_validations_green = true

  else
    all_validations_green = targets.map do |object_to_validate|
      if Helpers._marked_for_destruction?(object_to_validate)
        true
      else
        valid?(object_to_validate)
      end
    end.all?
  end

  call_failure(:unprocessable_entity, self.class.to_s.downcase.to_sym) unless all_validations_green
end