7
8
9
10
11
12
13
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
|
# File 'lib/glossarist/gcr_validator.rb', line 7
def validate(zip_path)
result = ValidationResult.new
unless File.exist?(zip_path)
result.add_error("File not found: #{zip_path}")
return result
end
begin
zip_entries = Zip::File.open(zip_path) { |zf| zf.entries.to_set(&:name) }
rescue StandardError => e
result.add_error("Failed to read ZIP: #{e.message}")
return result
end
unless zip_entries.include?("metadata.yaml")
result.add_error("Missing metadata.yaml")
return result
end
begin
context = Validation::Rules::GcrContext.new(zip_path)
rescue StandardError => e
result.add_error("Failed to load GCR: #{e.message}")
return result
end
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
concept_rules = Validation::Rules::Registry.for_scope(:concept)
context.concepts.each_with_index do |concept, idx|
fname = concept.data&.id ? "concepts/#{concept.data.id}.yaml" : "concepts/concept-#{idx}.yaml"
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
end
result
end
|