Class: Glossarist::GcrValidator

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

Instance Method Summary collapse

Instance Method Details

#validate(zip_path) ⇒ Object

rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity



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
# File 'lib/glossarist/gcr_validator.rb', line 7

def validate(zip_path) # rubocop:disable Metrics/AbcSize, Metrics/MethodLength, Metrics/CyclomaticComplexity, Metrics/PerceivedComplexity
  result = ValidationResult.new

  unless File.exist?(zip_path)
    result.add_error("File not found: #{zip_path}")
    return result
  end

  begin
    Zip::File.open(zip_path) do |zf|
      unless zf.find_entry("metadata.yaml")
        result.add_error("Missing metadata.yaml")
        return result
      end

       = GcrMetadata.from_yaml(
        zf.find_entry("metadata.yaml").get_input_stream.read,
      )
      (, result)

      concept_entries = zf.entries.select do |e|
        e.name.start_with?("concepts/") && e.name.end_with?(".yaml")
      end
      if concept_entries.empty?
        result.add_error("No concept files found in concepts/")
      end

      concept_entries.each do |entry|
        validate_concept_entry(entry, , result)
      end
    end
  rescue StandardError => e
    result.add_error("Failed to read ZIP: #{e.message}")
  end

  result
end