Class: Glossarist::ConceptValidator

Inherits:
Object
  • Object
show all
Defined in:
lib/glossarist/concept_validator.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(path, on_progress: nil) ⇒ ConceptValidator

Returns a new instance of ConceptValidator.



7
8
9
10
11
12
# File 'lib/glossarist/concept_validator.rb', line 7

def initialize(path, on_progress: nil)
  @path = path
  @on_progress = on_progress
  @errors = []
  @warnings = []
end

Instance Attribute Details

#errorsObject (readonly)

Returns the value of attribute errors.



5
6
7
# File 'lib/glossarist/concept_validator.rb', line 5

def errors
  @errors
end

#pathObject (readonly)

Returns the value of attribute path.



5
6
7
# File 'lib/glossarist/concept_validator.rb', line 5

def path
  @path
end

#warningsObject (readonly)

Returns the value of attribute warnings.



5
6
7
# File 'lib/glossarist/concept_validator.rb', line 5

def warnings
  @warnings
end

Instance Method Details

#validate_allObject



14
15
16
17
18
19
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
47
48
49
50
51
52
53
54
55
56
57
58
59
# File 'lib/glossarist/concept_validator.rb', line 14

def validate_all
  result = ValidationResult.new
  context = Validation::Rules::DatasetContext.new(@path)
  concept_rules = Validation::Rules::Registry.for_scope(:concept)
  total = ConceptCollector.count(@path)
  file_idx = 0

  ConceptCollector.each_concept(@path) do |concept|
    context.add_concept(concept)

    fname = concept_file_name(concept, file_idx)
    concept_context = Validation::Rules::ConceptContext.new(
      concept, file_name: fname, collection_context: context
    )

    concept_rules.each do |rule|
      next unless rule.applicable?(concept_context)

      rule.check(concept_context).each { |i| result.add_issue(i) }
    end

    file_idx += 1
    @on_progress&.call(file_idx, total)
  end

  if file_idx.zero?
    yaml_files = find_yaml_files
    if yaml_files.any?
      result.add_error("YAML files found but no parseable concepts")
    end
  end

  # Run collection-level rules
  collection_rules = Validation::Rules::Registry.for_scope(:collection)
  collection_rules.each do |rule|
    next unless rule.applicable?(context)

    rule.check(context).each { |i| result.add_issue(i) }
  end

  # Sync legacy arrays for backward compatibility
  @errors = result.errors
  @warnings = result.warnings

  result
end