lib/qyu/workers/concerns/payload_validator.rb
# Validates payload in processing task and raises a Qyu::Errors::PayloadValidationError
# if any of the conditions do not hold up
#
# @param [Task] task with payload
# @return [nil]
# @raise [Qyu::Errors::PayloadValidationError]
Validates payload in processing task and raises a Qyu::Errors::PayloadValidationError
if any of the conditions do not hold up
Validates payload in processing task and raises a Qyu :: Errors :: PayloadValidationError if any of the conditions do not hold up
def validate_payload!(model)
          return unless @_validations
          payload = Qyu::Utils.stringify_hash_keys(model.payload || {})
          validation_errors = {}
          @_validations.each do |attribute, opts|
            next unless if_validation(payload, opts['if'])
            next unless unless_validation(payload, opts['unless'])
            opts.map do |option, value|
              error = run_validation(option, payload[attribute.to_s], value)
              next unless error
              validation_errors["#{attribute}.#{option}"] = error
            end
          end
          if validation_errors.size.positive?
            fail Qyu::Errors::PayloadValidationError, validation_errors
          end
          nil
        end
def validate_payload! ( model ) return unless @_validations payload = Qyu :: Utils . stringify_hash_keys ( model . payload || { } ) validation_errors = { } @_validations . each do | attribute , opts | next unless if_validation ( payload , opts [ 'if' ] ) next unless unless_validation ( payload , opts [ 'unless' ] ) opts . map do | option , value | error = run_validation ( option , payload [ attribute . to_s ] , value ) next unless error validation_errors [ "#{attribute}.#{option}" ] = error end end if validation_errors . size . positive? fail Qyu :: Errors :: PayloadValidationError , validation_errors end nil end
Validates payload in processing task and raises a Qyu::Errors::PayloadValidationError
if any of the conditions do not hold up
Validates payload in processing task and raises a Qyu :: Errors :: PayloadValidationError if any of the conditions do not hold up
# example: attribute :name # example opts { presence: true, type: integer } # next if error is nil
None
nil
None
model
<not_specific>
<not_specific>
task with payload
task with payload