Class: Glossarist::Validation::Rules::DomainTargetRule

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

Overview

Validates that domain references point to concepts that exist in the dataset (for local refs with concept_id) or have a valid URN.

Constant Summary collapse

URN_RE =
%r{\Aurn:[a-z0-9][a-z0-9-]{0,31}:[a-z0-9()+,\-.:=@;$_!*'%/?#]+\z}i.freeze

Instance Method Summary collapse

Methods inherited from Base

inherited

Instance Method Details

#applicable?(context) ⇒ Boolean

Returns:

  • (Boolean)


16
17
18
# File 'lib/glossarist/validation/rules/domain_target_rule.rb', line 16

def applicable?(context)
  context.concept.data&.domains&.any?
end

#categoryObject



12
# File 'lib/glossarist/validation/rules/domain_target_rule.rb', line 12

def category = :references

#check(context) ⇒ Object



20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/glossarist/validation/rules/domain_target_rule.rb', line 20

def check(context)
  concept = context.concept
  fname = context.file_name
  issues = []

  (concept.data.domains || []).each_with_index do |domain, idx|
    if domain.concept_id && local_domain?(domain)
      unless context.concept_ids.include?(domain.concept_id)
        issues << issue(
          "domain #{idx + 1} references '#{domain.concept_id}' not in dataset",
          location: fname,
          suggestion: "Add concept '#{domain.concept_id}' or fix the domain ref",
        )
      end
    elsif domain.urn
      if domain.urn.start_with?("urn:") && !URN_RE.match?(domain.urn)
        issues << issue(
          "domain #{idx + 1} has invalid URN '#{domain.urn}'",
          location: fname,
          suggestion: "Fix the URN format",
        )
      end
    end
  end

  issues
end

#codeObject



11
# File 'lib/glossarist/validation/rules/domain_target_rule.rb', line 11

def code = "GLS-111"

#scopeObject



14
# File 'lib/glossarist/validation/rules/domain_target_rule.rb', line 14

def scope = :concept

#severityObject



13
# File 'lib/glossarist/validation/rules/domain_target_rule.rb', line 13

def severity = "warning"