Module: SpaceArchitect::XDG

Defined in:
lib/space_architect/xdg.rb

Class Method Summary collapse

Class Method Details

.config_home(env: ENV) ⇒ Object



9
10
11
# File 'lib/space_architect/xdg.rb', line 9

def config_home(env: ENV)
  Pathname.new(env.fetch("XDG_CONFIG_HOME", File.join(home(env: env), ".config")))
end

.expand_user(path, env: ENV) ⇒ Object



21
22
23
24
25
26
27
28
29
30
31
# File 'lib/space_architect/xdg.rb', line 21

def expand_user(path, env: ENV)
  value = path.to_s

  if value == "~"
    home(env: env)
  elsif value.start_with?("~/")
    File.join(home(env: env), value[2..])
  else
    File.expand_path(value)
  end
end

.home(env: ENV) ⇒ Object



17
18
19
# File 'lib/space_architect/xdg.rb', line 17

def home(env: ENV)
  env.fetch("HOME", Dir.home)
end

.state_home(env: ENV) ⇒ Object



13
14
15
# File 'lib/space_architect/xdg.rb', line 13

def state_home(env: ENV)
  Pathname.new(env.fetch("XDG_STATE_HOME", File.join(home(env: env), ".local", "state")))
end