Sha256: 443690b3028823618b3eaa1d5f587d1da95f5dd3c70ba5f2ff86c4fe94b7b63b

Contents?: true

Size: 890 Bytes

Versions: 3

Compression:

Stored size: 890 Bytes

Contents

module HashValidator
  module Validator
    class MultipleValidator < Base
      def initialize
        super('_multiple')  # The name of the validator, underscored as it won't usually be directly invoked (invoked through use of validator)
      end

      def should_validate?(validation)
        validation.is_a?(Validations::Multiple)
      end

      def validate(key, value, validations, errors)
        multiple_errors = []

        validations.validations.each do |validation|
          validation_error = {}
          ::HashValidator.validator_for(validation).validate(key, value, validation, validation_error)
          multiple_errors << validation_error[key] if validation_error[key]
        end

        errors[key] = multiple_errors.join(', ') if multiple_errors.any?
      end
    end
  end
end

HashValidator.append_validator(HashValidator::Validator::MultipleValidator.new)

Version data entries

3 entries across 3 versions & 1 rubygems

Version Path
hash_validator-1.1.0 lib/hash_validator/validators/multiple_validator.rb
hash_validator-1.0.0 lib/hash_validator/validators/multiple_validator.rb
hash_validator-0.8.0 lib/hash_validator/validators/multiple_validator.rb