Class: Dragnet::Validators::Fields::MetaDataFieldValidator

Inherits:
FieldValidator
  • Object
show all
Defined in:
lib/dragnet/validators/fields/meta_data_field_validator.rb

Overview

Base class to validate the fields that are part of the meta-data group. This means: Either String Array<String> or nil as value.

Instance Method Summary collapse

Instance Method Details

#validate(key, value) ⇒ nil, Array<String>

Validates the specified attribute as a meta-data field.

Parameters:

  • key (String)

    The name of the key

  • value (Object)

    The value of the key

Returns:

  • (nil)

    If value is nil or an empty array.

  • (Array<String>)

    If value is a String or an Arry<String>

Raises:



19
20
21
22
23
24
25
26
27
28
29
30
31
32
# File 'lib/dragnet/validators/fields/meta_data_field_validator.rb', line 19

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