module CommandKit::XDG

Provides access to [XDG directories].

## Environment Variables

[XDG directories]: specifications.freedesktop.org/basedir-spec/basedir-spec-latest.html

Attributes

cache_dir[R]

The `~/.cache/<xdg_namespace>` directory.

@return [String]

@api public

config_dir[R]

The `~/.config/<xdg_namespace>` directory.

@return [String]

@api public

local_share_dir[R]

The `~/.local/share/<xdg_namespace>` directory.

@return [String]

@api public

Public Class Methods

new(**kwargs) click to toggle source

Initializes {#config_dir}, {#local_share_dir}, and {#cache_dir}.

@param [Hash{Symbol => Object}] kwargs

Additional keyword arguments.

@note

If the `$XDG_CONFIG_HOME` env variable is set, then {#config_dir} will
be initialized to effectively `$XDG_CONFIG_HOME/<xdg_namespace>`.
Otherwise {#config_dir} will be initialized to
`~/.config/<xdg_namespace>`.

@note

If the `$XDG_DATA_HOME` env variable is set, then {#local_share_dir}
will be initialized to effectively `$XDG_DATA_HOME/<xdg_namespace>`.
Otherwise {#local_share_dir} will be initialized to
`~/.local/share/<xdg_namespace>`.

@note

If the `$XDG_CACHE_HOME` env variable is set, then {#cache_dir} will
be initialized to effectively `$XDG_CACHE_HOME/<xdg_namespace>`.
Otherwise {#cache_dir} will be initialized to
`~/.cache/<xdg_namespace>`.
Calls superclass method CommandKit::Env::Home::new
# File lib/command_kit/xdg.rb, line 127
def initialize(**kwargs)
  super(**kwargs)

  xdg_config_home = env.fetch('XDG_CONFIG_HOME') do
    File.join(home_dir,'.config')
  end

  @config_dir = File.join(xdg_config_home,xdg_namespace)

  xdg_data_home = env.fetch('XDG_DATA_HOME') do
    File.join(home_dir,'.local','share')
  end

  @local_share_dir = File.join(xdg_data_home,xdg_namespace)

  xdg_cache_home = env.fetch('XDG_CACHE_HOME') do
    File.join(home_dir,'.cache')
  end

  @cache_dir = File.join(xdg_cache_home,xdg_namespace)
end

Public Instance Methods

xdg_namespace() click to toggle source

@see ClassMethods#xdg_namespace

@api semipublic

# File lib/command_kit/xdg.rb, line 154
def xdg_namespace
  self.class.xdg_namespace
end