Class: Glossarist::Validation::Rules::RelatedConceptSymmetryRule

Inherits:
Base
  • Object
show all
Defined in:
lib/glossarist/validation/rules/related_concept_symmetry_rule.rb

Constant Summary collapse

INVERSE =
{
  "supersedes" => "superseded_by",
  "superseded_by" => "supersedes",
  "narrower" => "broader",
  "broader" => "narrower",
  "deprecates" => "deprecated_by",
  "deprecated_by" => "deprecates",
}.freeze
DIRECTIONAL =
%w[supersedes deprecates narrower].freeze

Instance Method Summary collapse

Methods inherited from Base

inherited

Instance Method Details

#applicable?(context) ⇒ Boolean

Returns:

  • (Boolean)


23
24
25
# File 'lib/glossarist/validation/rules/related_concept_symmetry_rule.rb', line 23

def applicable?(context)
  context.concepts.any? { |c| c.related&.any? }
end

#categoryObject



8
# File 'lib/glossarist/validation/rules/related_concept_symmetry_rule.rb', line 8

def category = :references

#check(context) ⇒ Object



27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
52
53
54
# File 'lib/glossarist/validation/rules/related_concept_symmetry_rule.rb', line 27

def check(context)
  index = build_relation_index(context.concepts)
  issues = []

  context.concepts.each do |concept|
    next unless concept.related&.any?

    concept_id = concept.data&.id&.to_s || "unknown"
    (concept.related || []).each do |rel|
      inverse = INVERSE[rel.type]
      next unless inverse

      target_id = resolve_target_id(rel)
      next unless target_id

      targets = index[target_id]
      next if targets && targets.any? { |r| r.type == inverse }

      issues << issue(
        "#{concept_id}: #{rel.type} #{target_id} but #{target_id} has no #{inverse} back-link",
        location: concept_id,
        suggestion: "Add a #{inverse} relation on #{target_id} pointing back to #{concept_id}",
      )
    end
  end

  issues
end

#codeObject



7
# File 'lib/glossarist/validation/rules/related_concept_symmetry_rule.rb', line 7

def code = "GLS-112"

#scopeObject



10
# File 'lib/glossarist/validation/rules/related_concept_symmetry_rule.rb', line 10

def scope = :collection

#severityObject



9
# File 'lib/glossarist/validation/rules/related_concept_symmetry_rule.rb', line 9

def severity = "warning"