Class: Cocina::Models::Validators::AssociatedNameValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/cocina/models/validators/associated_name_validator.rb

Overview

Validates that when title.note with type “associated name” has a value, it must match a contributor name.

Class Method Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(clazz, attributes) ⇒ AssociatedNameValidator

Returns a new instance of AssociatedNameValidator.



12
13
14
15
16
# File 'lib/cocina/models/validators/associated_name_validator.rb', line 12

def initialize(clazz, attributes)
  @clazz = clazz
  @attributes = attributes
  @error_paths = []
end

Class Method Details

.validate(clazz, attributes) ⇒ Object



8
9
10
# File 'lib/cocina/models/validators/associated_name_validator.rb', line 8

def self.validate(clazz, attributes)
  new(clazz, attributes).validate
end

Instance Method Details

#validateObject

Raises:



18
19
20
21
22
23
24
25
# File 'lib/cocina/models/validators/associated_name_validator.rb', line 18

def validate
  return unless meets_preconditions?

  return if resources.all? { |resource| valid?(resource) }

  raise ValidationError,
        'Missing data: Name associated with uniform title does not match any contributor.'
end