Module: Kotoshu::Paths

Defined in:
lib/kotoshu/paths.rb

Overview

Centralized XDG Base Directory paths.

Resolves cache, config, and data paths per the XDG Base Directory Specification. Kotoshu-specific env vars (KOTOSHU_CACHE_PATH etc.) take precedence over the generic XDG_*_HOME vars, which take precedence over the hardcoded defaults.

Default layout:

~/.cache/kotoshu/         downloaded dicts, models, frequency lists
~/.config/kotoshu/        user-edited config, personal dictionary
~/.local/share/kotoshu/   append-only data (audit log)

Class Method Summary collapse

Class Method Details

.audit_log_pathObject



31
32
33
# File 'lib/kotoshu/paths.rb', line 31

def audit_log_path
  ENV.fetch("KOTOSHU_AUDIT_LOG", nil) || File.join(data_path, "audit.log")
end

.cache_pathObject



19
20
21
# File 'lib/kotoshu/paths.rb', line 19

def cache_path
  ENV.fetch("KOTOSHU_CACHE_PATH", nil) || xdg("CACHE", "cache")
end

.config_pathObject



23
24
25
# File 'lib/kotoshu/paths.rb', line 23

def config_path
  ENV.fetch("KOTOSHU_CONFIG_PATH", nil) || xdg("CONFIG", "config")
end

.data_pathObject



27
28
29
# File 'lib/kotoshu/paths.rb', line 27

def data_path
  ENV.fetch("KOTOSHU_DATA_PATH", nil) || xdg("DATA", "local/share")
end

.ensure_exist!Object



39
40
41
42
43
# File 'lib/kotoshu/paths.rb', line 39

def ensure_exist!
  FileUtils.mkdir_p(cache_path)
  FileUtils.mkdir_p(config_path)
  FileUtils.mkdir_p(data_path)
end

.personal_dictionary_pathObject



35
36
37
# File 'lib/kotoshu/paths.rb', line 35

def personal_dictionary_path
  ENV.fetch("KOTOSHU_PERSONAL_DIC", nil) || File.join(config_path, "personal.dic")
end