Class: Hyrax::FlexibleSchemaValidators::ClassValidator
- Inherits:
-
Object
- Object
- Hyrax::FlexibleSchemaValidators::ClassValidator
- Defined in:
- app/services/hyrax/flexible_schema_validators/class_validator.rb
Overview
Handles class-related validations for flexible metadata profiles
Instance Method Summary collapse
-
#initialize(profile, required_classes, errors) ⇒ ClassValidator
constructor
A new instance of ClassValidator.
-
#validate_availability! ⇒ void
Validates that referenced classes are registered Hyrax curation concern types and that Valkyrie models use the correct
...Resourcenaming convention when applicable. -
#validate_references! ⇒ void
Validates that all classes referenced within property
available_ondefinitions are themselves defined in the top-levelclassessection of the profile.
Constructor Details
#initialize(profile, required_classes, errors) ⇒ ClassValidator
Returns a new instance of ClassValidator.
10 11 12 13 14 |
# File 'app/services/hyrax/flexible_schema_validators/class_validator.rb', line 10 def initialize(profile, required_classes, errors) @profile = profile @required_classes = required_classes @errors = errors end |
Instance Method Details
#validate_availability! ⇒ void
This method returns an undefined value.
Validates that referenced classes are registered Hyrax curation concern types and that Valkyrie models use the correct ...Resource naming convention when applicable.
21 22 23 24 25 26 27 28 29 30 31 32 |
# File 'app/services/hyrax/flexible_schema_validators/class_validator.rb', line 21 def validate_availability! classes_to_validate = all_profile_classes - @required_classes invalid_classes = [] mismatched_valkyrie_classes = [] classes_to_validate.each do |klass| validate_class(klass, invalid_classes, mismatched_valkyrie_classes) end report_mismatched_classes(mismatched_valkyrie_classes) report_invalid_classes(invalid_classes) end |
#validate_references! ⇒ void
This method returns an undefined value.
Validates that all classes referenced within property available_on definitions are themselves defined in the top-level classes section of the profile.
39 40 41 42 43 44 45 46 47 48 49 50 51 |
# File 'app/services/hyrax/flexible_schema_validators/class_validator.rb', line 39 def validate_references! properties = @profile['properties'] || {} referenced_classes = properties.values.flat_map do |prop| prop.dig('available_on', 'class') end.compact.uniq undefined_classes = referenced_classes - @profile['classes'].keys return if undefined_classes.empty? @errors << "Classes referenced in `available_on` but not defined in `classes`: #{undefined_classes.join(', ')}." end |