Class: Cocina::Models::Validators::DescriptionValuesVisitorValidator

Inherits:
BaseDescriptionVisitorValidator show all
Defined in:
lib/cocina/models/validators/description_values_visitor_validator.rb

Overview

Validates that there is only one of value, groupedValue, structuredValue, or parallelValue, that values are not blank, and that title structuredValue entries have a type.

Instance Method Summary collapse

Methods inherited from BaseDescriptionVisitorValidator

#path_to_s, #visit_array, #visit_obj

Instance Method Details

#validate!Object

Raises:



15
16
17
18
19
20
21
22
23
24
25
26
27
28
# File 'lib/cocina/models/validators/description_values_visitor_validator.rb', line 15

def validate!
  unless error_paths_multiple.empty?
    raise ValidationError,
          "Multiple value, groupedValue, structuredValue, and parallelValue in description: #{error_paths_multiple.join(', ')}"
  end
  unless error_paths_blank.empty?
    raise ValidationError,
          "Blank value in description: #{error_paths_blank.join(', ')}"
  end
  return if error_paths_missing_title_type.empty?

  raise ValidationError,
        "Missing type for value in description: #{error_paths_missing_title_type.join(', ')}"
end

#visit_hash(hash:, path:) ⇒ Object



9
10
11
12
13
# File 'lib/cocina/models/validators/description_values_visitor_validator.rb', line 9

def visit_hash(hash:, path:)
  validate_values_for_blanks(hash, path)
  validate_values_for_multiples(hash, path)
  validate_title_type(hash, path)
end