Sha256: 04b4a27766a8fc44a6da3d4a1803efa4cd2b8b26e2e7d57e857c7fe938e1fc68
Contents?: true
Size: 1.13 KB
Versions: 3
Compression:
Stored size: 1.13 KB
Contents
# frozen_string_literal: true require_relative 'field_validator' require_relative '../../errors/validation_error' module Dragnet module Validators module Fields # Base class to validate the fields that are part of the meta-data group. # This means: Either +String+ +Array<String>+ or +nil+ as value. class MetaDataFieldValidator < Dragnet::Validators::Fields::FieldValidator # Validates the specified attribute as a meta-data field. # @param [String] key The name of the key # @param [Object] value The value of the key # @raise [Dragnet::Errors::ValidationError] If the attribute fails the # validation. # @return [nil] If +value+ is +nil+ or an empty array. # @return [Array<String>] If +value+ is a +String+ or an +Arry<String>+ def validate(key, value) return unless value validate_type(key, value, String, Array) if value.is_a?(Array) return if value.empty? validate_array_types(key, value, String) value else [value] end end end end end end
Version data entries
3 entries across 3 versions & 1 rubygems