Class: Teems::Support::XdgPaths

Inherits:
Object
  • Object
show all
Defined in:
lib/teems/support/xdg_paths.rb

Overview

XDG-compliant paths for config, cache, and data directories

Instance Method Summary collapse

Instance Method Details

#cache_dirObject



14
15
16
17
18
19
# File 'lib/teems/support/xdg_paths.rb', line 14

def cache_dir
  @cache_dir ||= File.join(
    ENV.fetch('XDG_CACHE_HOME', File.join(Dir.home, '.cache')),
    'teems'
  )
end

#cache_file(filename) ⇒ Object



32
33
34
# File 'lib/teems/support/xdg_paths.rb', line 32

def cache_file(filename)
  File.join(cache_dir, filename)
end

#config_dirObject



7
8
9
10
11
12
# File 'lib/teems/support/xdg_paths.rb', line 7

def config_dir
  @config_dir ||= File.join(
    ENV.fetch('XDG_CONFIG_HOME', File.join(Dir.home, '.config')),
    'teems'
  )
end

#config_file(filename) ⇒ Object



28
29
30
# File 'lib/teems/support/xdg_paths.rb', line 28

def config_file(filename)
  File.join(config_dir, filename)
end

#data_dirObject



21
22
23
24
25
26
# File 'lib/teems/support/xdg_paths.rb', line 21

def data_dir
  @data_dir ||= File.join(
    ENV.fetch('XDG_DATA_HOME', File.join(Dir.home, '.local', 'share')),
    'teems'
  )
end

#data_file(filename) ⇒ Object



36
37
38
# File 'lib/teems/support/xdg_paths.rb', line 36

def data_file(filename)
  File.join(data_dir, filename)
end

#ensure_cache_dirObject



47
48
49
50
51
52
# File 'lib/teems/support/xdg_paths.rb', line 47

def ensure_cache_dir
  FileUtils.mkdir_p(cache_dir)
rescue SystemCallError => e
  warn "teems: Could not create cache directory #{cache_dir}: #{e.message}"
  raise
end

#ensure_config_dirObject



40
41
42
43
44
45
# File 'lib/teems/support/xdg_paths.rb', line 40

def ensure_config_dir
  FileUtils.mkdir_p(config_dir)
rescue SystemCallError => e
  warn "teems: Could not create config directory #{config_dir}: #{e.message}"
  raise
end

#ensure_data_dirObject



54
55
56
57
58
59
# File 'lib/teems/support/xdg_paths.rb', line 54

def ensure_data_dir
  FileUtils.mkdir_p(data_dir)
rescue SystemCallError => e
  warn "teems: Could not create data directory #{data_dir}: #{e.message}"
  raise
end