Class: Glossarist::Validation::Rules::LocalizationConsistencyRule
- Defined in:
- lib/glossarist/validation/rules/localization_consistency_rule.rb
Overview
Verifies that every entry in localized_concepts map points to a loaded localization, and that every loaded localization has a corresponding entry in the map.
Instance Method Summary collapse
- #applicable?(context) ⇒ Boolean
- #category ⇒ Object
- #check(context) ⇒ Object
- #code ⇒ Object
- #scope ⇒ Object
- #severity ⇒ Object
Methods inherited from Base
Instance Method Details
#applicable?(context) ⇒ Boolean
15 16 17 18 |
# File 'lib/glossarist/validation/rules/localization_consistency_rule.rb', line 15 def applicable?(context) context.concept.localizations&.any? || context.concept.data&.localized_concepts&.any? end |
#category ⇒ Object
11 |
# File 'lib/glossarist/validation/rules/localization_consistency_rule.rb', line 11 def category = :integrity |
#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 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/glossarist/validation/rules/localization_consistency_rule.rb', line 20 def check(context) concept = context.concept fname = context.file_name issues = [] lc_map = concept.data&.localized_concepts || {} loaded_langs = concept.localizations&.map(&:language_code)&.compact || [] # Map has entry but no loaded localization lc_map.each_key do |lang| next if loaded_langs.include?(lang) issues << issue( "localized_concepts map has '#{lang}' but no localization loaded", location: fname, suggestion: "Add a localization for '#{lang}' or remove it from the map", ) end # Loaded localization not in map loaded_langs.each do |lang| next if lc_map.key?(lang) issues << issue( "localization '#{lang}' is loaded but not in localized_concepts map", location: fname, suggestion: "Add '#{lang}' to the localized_concepts map", ) end # UUID mismatch between map and loaded localization concept.localizations.each do |l10n| lang = l10n.language_code next unless lang expected_uuid = lc_map[lang] actual_uuid = l10n.uuid next unless expected_uuid && actual_uuid next if expected_uuid == actual_uuid issues << issue( "UUID mismatch for '#{lang}': map says '#{expected_uuid}', localization is '#{actual_uuid}'", location: fname, suggestion: "Ensure the UUID in the map matches the localization file", ) end issues end |
#code ⇒ Object
10 |
# File 'lib/glossarist/validation/rules/localization_consistency_rule.rb', line 10 def code = "GLS-017" |
#scope ⇒ Object
13 |
# File 'lib/glossarist/validation/rules/localization_consistency_rule.rb', line 13 def scope = :concept |
#severity ⇒ Object
12 |
# File 'lib/glossarist/validation/rules/localization_consistency_rule.rb', line 12 def severity = "error" |