Class: Opencdd::Validator::ClassReferenceRule
- Defined in:
- lib/opencdd/validator/class_reference_rule.rb
Overview
R16 — CLASS_REFERENCE target validation.
When a property's data_type is CLASS_REFERENCE(CategoricalClass)
(or the column carries a CLASS_REFERENCE schema), the value IRDI
must resolve to an entity that is a valid powertype instance of
the named categorical class — i.e. one of its
categorical_instances.
This rule closes the loop on CDD's powertype semantics: a CLASS_REFERENCE data type doesn't just say "this is an IRDI"; it says "this is an IRDI of an instance of this categorical class." Plain reference resolution (R08) doesn't catch the categorical constraint.
Example: a Property engine_type: CLASS_REFERENCE(EngineType)
whose value is "AAA001" (Vehicle) should fail — Vehicle is
not a categorical instance of EngineType. Only SingleDiesel /
TwinDiesel / ElectricHybrid (EngineType's subclasses) pass.
Constant Summary
Constants inherited from Rule
Instance Method Summary collapse
- #applies?(context) ⇒ Boolean
- #call(value, context) ⇒ Object
- #id ⇒ Object
- #message(value, context) ⇒ Object
Methods inherited from Rule
#blank?, #code_column?, #reference_kind?, #skip_blank?, #value_passes?
Instance Method Details
#applies?(context) ⇒ Boolean
28 29 30 31 32 |
# File 'lib/opencdd/validator/class_reference_rule.rb', line 28 def applies?(context) return false unless context.database parsed = parse_data_type(context) parsed.is_a?(Opencdd::DataType::ClassReference) end |
#call(value, context) ⇒ Object
34 35 36 37 38 39 40 |
# File 'lib/opencdd/validator/class_reference_rule.rb', line 34 def call(value, context) return true if value.nil? || value.to_s.strip.empty? target = categorical_target(context) return true unless target # cannot validate without target resolution refs(value).all? { |ref| context.database.valid_class_reference?(target, ref) } end |
#id ⇒ Object
24 25 26 |
# File 'lib/opencdd/validator/class_reference_rule.rb', line 24 def id "R16" end |
#message(value, context) ⇒ Object
42 43 44 45 46 |
# File 'lib/opencdd/validator/class_reference_rule.rb', line 42 def (value, context) target = categorical_target(context) name = target ? target.code : "<unresolved>" "R16: CLASS_REFERENCE(#{name}) value #{value.inspect} is not a valid powertype instance" end |