Class: Opencdd::Validator::Runner
- Inherits:
-
Object
- Object
- Opencdd::Validator::Runner
- Defined in:
- lib/opencdd/validator/runner.rb
Defined Under Namespace
Classes: RuleContext
Constant Summary collapse
- RULES =
[ IrdiRule.new, UniquenessRule.new, MandatoryRule.new, TypeRule.new, EnumRule.new, FormatRule.new, PatternRule.new, ReferenceRule.new, SetRule.new, SynonymRule.new, ConditionRule.new, DataTypeRule.new, ClassReferenceRule.new, ].freeze
Class Method Summary collapse
- .build_context(database:, entity:, column_iri:, value:, schema:, meta:, enum_terms_resolver:) ⇒ Object
- .derived_data_type(entity, base, column_schema) ⇒ Object
- .run(database, enum_terms_resolver: nil) ⇒ Object
- .validate_entity(entity, database, errors, enum_terms_resolver) ⇒ Object
Class Method Details
.build_context(database:, entity:, column_iri:, value:, schema:, meta:, enum_terms_resolver:) ⇒ Object
76 77 78 79 80 81 82 83 84 85 86 87 88 89 90 91 92 |
# File 'lib/opencdd/validator/runner.rb', line 76 def self.build_context(database:, entity:, column_iri:, value:, schema:, meta:, enum_terms_resolver:) base = column_iri.to_s.split(".").first entry = Opencdd::PropertyIds::REGISTRY[base] kind = entry&.value_kind column_schema = schema&.column_for(base) RuleContext.new( database: database, entity: entity, column_iri: base, value_kind: kind, data_type: derived_data_type(entity, base, column_schema), value_format: column_schema&.value_format, pattern: column_schema&.pattern, requirement: column_schema&.requirement, enum_terms_resolver: enum_terms_resolver, ) end |
.derived_data_type(entity, base, column_schema) ⇒ Object
94 95 96 97 98 |
# File 'lib/opencdd/validator/runner.rb', line 94 def self.derived_data_type(entity, base, column_schema) return column_schema&.data_type if column_schema&.data_type return entity.data_type if entity.is_a?(Opencdd::Property) && base == Opencdd::PropertyIds::MDC_P022 nil end |
.run(database, enum_terms_resolver: nil) ⇒ Object
38 39 40 41 42 43 44 45 46 47 48 49 50 |
# File 'lib/opencdd/validator/runner.rb', line 38 def self.run(database, enum_terms_resolver: nil) errors = [] database.entities.each do |entity| validate_entity(entity, database, errors, enum_terms_resolver) end unless HierarchyRule.class_hierarchy_acyclic?(database) errors << ValidationError.new( sheet: nil, row: nil, column: nil, rule: "R14", message: "R14: class hierarchy contains a cycle", ) end errors end |
.validate_entity(entity, database, errors, enum_terms_resolver) ⇒ Object
52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 69 70 71 72 73 74 |
# File 'lib/opencdd/validator/runner.rb', line 52 def self.validate_entity(entity, database, errors, enum_terms_resolver) = Opencdd::MetaClasses.for(entity.&.code) schema = entity.schema entity.each_property do |column_iri, value| next if column_iri == "__row_index__" context = build_context( database: database, entity: entity, column_iri: column_iri, value: value, schema: schema, meta: , enum_terms_resolver: enum_terms_resolver, ) RULES.each do |rule| next unless rule.applies?(context) next if rule.call(value, context) errors << ValidationError.new( sheet: entity.&.code, row: entity.irdi&.to_s, column: column_iri, rule: rule.id, message: rule.(value, context), ) end end end |