Class: Glossarist::Validation::Rules::FilenameIdRule

Inherits:
Base
  • Object
show all
Defined in:
lib/glossarist/validation/rules/filename_id_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/filename_id_rule.rb', line 12

def applicable?(context)
  context.gcr?
end

#categoryObject



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

def category = :integrity

#check(context) ⇒ Object



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
# File 'lib/glossarist/validation/rules/filename_id_rule.rb', line 16

def check(context)
  concept = context.concept
  fname = context.file_name
  expected_id = concept.data&.id&.to_s
  actual_name = fname.sub(/\.yaml\z/, "").sub(%r{\Aconcepts/}, "")

  return [] unless expected_id && expected_id != actual_name

  [issue(
    "filename '#{actual_name}' does not match concept id '#{expected_id}'",
    code: code, severity: severity,
    location: "concepts/#{fname}",
    suggestion: "Rename the entry or fix the concept id",
  )]
end

#codeObject



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

def code = "GLS-015"

#scopeObject



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

def scope = :concept

#severityObject



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

def severity = "error"