Class: Glossarist::Validation::Rules::ConceptIdUniquenessRule

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

Instance Method Summary collapse

Methods inherited from Base

inherited

Instance Method Details

#applicable?(context) ⇒ Boolean

Returns:

  • (Boolean)


12
13
14
# File 'lib/glossarist/validation/rules/concept_id_uniqueness_rule.rb', line 12

def applicable?(context)
  context.concepts.any?
end

#categoryObject



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

def category = :structure

#check(context) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/glossarist/validation/rules/concept_id_uniqueness_rule.rb', line 16

def check(context)
  issues = []
  seen_ids = {}

  context.concepts.each_with_index do |concept, idx|
    id = concept.data&.id&.to_s
    fname = id ? "concept-#{id}.yaml" : "concept-#{idx}.yaml"

    next unless id

    if seen_ids[id]
      issues << issue(
        "#{fname}: duplicate id '#{id}' (first seen in #{seen_ids[id]})",
        code: code, severity: "error",
      )
    else
      seen_ids[id] = fname
    end
  end

  issues
end

#codeObject



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

def code = "GLS-001-uniq"

#scopeObject



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

def scope = :collection

#severityObject



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

def severity = "error"