module GemHadar::Utils

def xdg_config(name, default)

Returns:
  • (String) - the content of the configuration file or the default value

Parameters:
  • default (Object) -- the default value to return if the configuration file is not found
  • name (String) -- the name of the configuration file to retrieve
def xdg_config(name, default)
  if File.exist?(xdg_config_filename(name))
    File.read(xdg_config_filename(name))
  else
    default
  end
end

def xdg_config_filename(name)

Returns:
  • (String) - the full path to the configuration file

Parameters:
  • name (String) -- the name of the configuration file
def xdg_config_filename(name)
  xdg_config_home + name
end

def xdg_config_home

Returns:
  • (Pathname) - the Pathname object representing the XDG configuration directory
def xdg_config_home
  ENV['XDG_CONFIG_HOME'].full? { Pathname.new(_1) } ||
    Pathname.new(ENV.fetch('HOME')) + '.config'
end