Module: Fontisan::Cldr::CacheManager
- Defined in:
- lib/fontisan/cldr/cache_manager.rb
Overview
Manages the on-disk CLDR cache layout.
Cache root resolution honors XDG_CONFIG_HOME per the XDG Base
Directory Specification. Falls back to ~/.config on Unix.
Layout:
<root>/
<version>/
json/ # extracted CLDR JSON archive
cldr-json/
cldr-characters-full/
main/<lang>/characters.json
index/
languages.yml # built index of per-language codepoint sets
No network access — all methods are pure filesystem operations.
Class Method Summary collapse
-
.cached?(version) ⇒ Boolean
True if the extracted JSON archive is present for this version.
-
.cached_versions ⇒ Array<String>
All versions currently in the cache (sorted ascending).
-
.characters_main_dir(version) ⇒ Pathname
Directory containing the per-language characters.json files inside the extracted archive.
-
.ensure_version_dir!(version) ⇒ Object
Create the version directory and json/index subdirs.
-
.index_dir(version) ⇒ Pathname
Directory holding the derived language index for a version.
-
.json_dir(version) ⇒ Pathname
Directory where the raw CLDR JSON archive is extracted.
- .languages_index_path(version) ⇒ Object
-
.remove_version(version) ⇒ Object
Remove a version from the cache.
-
.root ⇒ Pathname
Root path of the CLDR cache.
-
.version_dir(version) ⇒ Pathname
Per-version directory.
Class Method Details
.cached?(version) ⇒ Boolean
True if the extracted JSON archive is present for this version.
72 73 74 |
# File 'lib/fontisan/cldr/cache_manager.rb', line 72 def cached?(version) characters_main_dir(version).exist? end |
.cached_versions ⇒ Array<String>
All versions currently in the cache (sorted ascending).
78 79 80 81 82 |
# File 'lib/fontisan/cldr/cache_manager.rb', line 78 def cached_versions return [] unless root.exist? root.children.select(&:directory?).map { |p| p.basename.to_s }.sort end |
.characters_main_dir(version) ⇒ Pathname
Directory containing the per-language characters.json files inside the extracted archive.
54 55 56 |
# File 'lib/fontisan/cldr/cache_manager.rb', line 54 def characters_main_dir(version) json_dir(version).join("cldr-json", "cldr-characters-full", "main") end |
.ensure_version_dir!(version) ⇒ Object
Create the version directory and json/index subdirs. Idempotent.
87 88 89 90 |
# File 'lib/fontisan/cldr/cache_manager.rb', line 87 def ensure_version_dir!(version) json_dir(version).mkpath index_dir(version).mkpath end |
.index_dir(version) ⇒ Pathname
Directory holding the derived language index for a version.
61 62 63 |
# File 'lib/fontisan/cldr/cache_manager.rb', line 61 def index_dir(version) version_dir(version).join("index") end |
.json_dir(version) ⇒ Pathname
Directory where the raw CLDR JSON archive is extracted.
46 47 48 |
# File 'lib/fontisan/cldr/cache_manager.rb', line 46 def json_dir(version) version_dir(version).join("json") end |
.languages_index_path(version) ⇒ Object
65 66 67 |
# File 'lib/fontisan/cldr/cache_manager.rb', line 65 def languages_index_path(version) index_dir(version).join(LANGUAGES_INDEX_FILENAME) end |
.remove_version(version) ⇒ Object
Remove a version from the cache. No-op if absent.
94 95 96 97 |
# File 'lib/fontisan/cldr/cache_manager.rb', line 94 def remove_version(version) dir = version_dir(version) dir.rmtree if dir.exist? end |
.root ⇒ Pathname
Root path of the CLDR cache.
31 32 33 34 |
# File 'lib/fontisan/cldr/cache_manager.rb', line 31 def root base = xdg_config_home || File.join(Dir.home, ".config") Pathname.new(base).join("fontisan", "cldr") end |
.version_dir(version) ⇒ Pathname
Per-version directory.
39 40 41 |
# File 'lib/fontisan/cldr/cache_manager.rb', line 39 def version_dir(version) root.join(version) end |