Module: GemHadar::Utils
- Included in:
- GemHadar
- Defined in:
- lib/gem_hadar/utils.rb
Overview
A module that provides utility methods for handling XDG Base Directory specification compliance.
This module offers functionality to determine the appropriate configuration directory based on the XDG Base Directory specification, construct paths for configuration files, and retrieve configuration data from those files. It helps ensure consistent and standardized handling of user configuration files across different operating systems.
Instance Method Summary collapse
-
#xdg_config_filename(name) ⇒ String
The xdg_config_filename method constructs the full path to a configuration file based on the XDG Base Directory specification.
-
#xdg_config_home ⇒ Pathname
The xdg_config_home method determines the path to the XDG configuration directory.
Instance Method Details
#xdg_config_filename(name) ⇒ String
The xdg_config_filename method constructs the full path to a configuration file based on the XDG Base Directory specification.
It first checks if the XDG_CONFIG_HOME environment variable is set and not empty. If it is set, the method joins this directory with the provided filename to form the complete path. If XDG_CONFIG_HOME is not set, it defaults to using the HOME environment variable to construct the path within the standard .config directory.
44 45 46 |
# File 'lib/gem_hadar/utils.rb', line 44 def xdg_config_filename(name) xdg_config_home + name end |
#xdg_config_home ⇒ Pathname
The xdg_config_home method determines the path to the XDG configuration directory.
It first checks if the XDG_CONFIG_HOME environment variable is set and not empty. If it is set, the method returns the value as a Pathname object. If XDG_CONFIG_HOME is not set, it defaults to using the HOME environment variable to construct the path within the standard .config directory.
27 28 29 30 |
# File 'lib/gem_hadar/utils.rb', line 27 def xdg_config_home ENV['XDG_CONFIG_HOME'].full? { Pathname.new(_1) } || Pathname.new(ENV.fetch('HOME')) + '.config' end |