Module: Fontisan::Ucd::CacheManager

Defined in:
lib/fontisan/ucd/cache_manager.rb

Overview

Manages the on-disk UCD cache layout.

Cache root resolution honors XDG_CONFIG_HOME per the XDG Base Directory Specification. Falls back to ~/.config on Unix and ~/.config (literal) elsewhere — consistent with other Fontisan config paths.

Layout:

<root>/
<version>/
  ucdxml/
    ucd.all.flat.xml
  index/
    blocks.yml
    scripts.yml

No network access — all methods are pure filesystem operations.

Class Method Summary collapse

Class Method Details

.blocks_index_path(version) ⇒ Object



62
63
64
# File 'lib/fontisan/ucd/cache_manager.rb', line 62

def blocks_index_path(version)
  index_dir(version).join(BLOCKS_INDEX_FILENAME)
end

.cached?(version) ⇒ Boolean

True if the UCDXML file is present for this version.

Parameters:

  • version (String)

Returns:

  • (Boolean)


73
74
75
# File 'lib/fontisan/ucd/cache_manager.rb', line 73

def cached?(version)
  ucdxml_path(version).exist?
end

.cached_versionsArray<String>

All versions currently in the cache (sorted ascending).

Returns:

  • (Array<String>)


79
80
81
82
83
# File 'lib/fontisan/ucd/cache_manager.rb', line 79

def cached_versions
  return [] unless root.exist?

  root.children.select(&:directory?).map { |p| p.basename.to_s }.sort
end

.ensure_version_dir!(version) ⇒ Object

Create the version directory and ucdxml/index subdirs. Idempotent.

Parameters:

  • version (String)


88
89
90
91
# File 'lib/fontisan/ucd/cache_manager.rb', line 88

def ensure_version_dir!(version)
  ucdxml_path(version).dirname.mkpath
  index_dir(version).mkpath
end

.index_dir(version) ⇒ Pathname

Directory holding the derived RLE indices for a version.

Parameters:

  • version (String)

Returns:

  • (Pathname)


58
59
60
# File 'lib/fontisan/ucd/cache_manager.rb', line 58

def index_dir(version)
  version_dir(version).join("index")
end

.remove_version(version) ⇒ Object

Remove a version from the cache. No-op if absent.

Parameters:

  • version (String)


95
96
97
98
# File 'lib/fontisan/ucd/cache_manager.rb', line 95

def remove_version(version)
  dir = version_dir(version)
  dir.rmtree if dir.exist?
end

.rootPathname

Root path of the UCD cache.

Returns:

  • (Pathname)


36
37
38
39
# File 'lib/fontisan/ucd/cache_manager.rb', line 36

def root
  base = xdg_config_home || File.join(Dir.home, ".config")
  Pathname.new(base).join("fontisan", "unicode")
end

.scripts_index_path(version) ⇒ Object



66
67
68
# File 'lib/fontisan/ucd/cache_manager.rb', line 66

def scripts_index_path(version)
  index_dir(version).join(SCRIPTS_INDEX_FILENAME)
end

.ucdxml_path(version) ⇒ Pathname

Path to the unpacked UCDXML flat file for a version.

Parameters:

  • version (String)

Returns:

  • (Pathname)


51
52
53
# File 'lib/fontisan/ucd/cache_manager.rb', line 51

def ucdxml_path(version)
  version_dir(version).join("ucdxml", UCDXML_FILENAME)
end

.version_dir(version) ⇒ Pathname

Per-version directory.

Parameters:

  • version (String)

    e.g. "17.0.0"

Returns:

  • (Pathname)


44
45
46
# File 'lib/fontisan/ucd/cache_manager.rb', line 44

def version_dir(version)
  root.join(version)
end