gem_hadar 1.25.0 → 1.27.0

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
@@ -1,13 +1,48 @@
1
+ require 'pathname'
2
+
1
3
  module GemHadar::Utils
4
+ # The xdg_config_home method determines the path to the XDG configuration
5
+ # directory.
6
+ #
7
+ # It first checks if the XDG_CONFIG_HOME environment variable is set and not
8
+ # empty. If it is set, the method returns the value as a Pathname object. If
9
+ # XDG_CONFIG_HOME is not set, it defaults to using the HOME environment
10
+ # variable to construct the path within the standard .config directory.
11
+ #
12
+ # @return [ Pathname ] the Pathname object representing the XDG configuration directory
13
+ def xdg_config_home
14
+ ENV['XDG_CONFIG_HOME'].full? { Pathname.new(_1) } ||
15
+ Pathname.new(ENV.fetch('HOME')) + '.config'
16
+ end
17
+
18
+ # The xdg_config_filename method constructs the full path to a configuration
19
+ # file based on the XDG Base Directory specification.
20
+ #
21
+ # It first checks if the XDG_CONFIG_HOME environment variable is set and not
22
+ # empty. If it is set, the method joins this directory with the provided
23
+ # filename to form the complete path. If XDG_CONFIG_HOME is not set, it
24
+ # defaults to using the HOME environment variable to construct the path
25
+ # within the standard .config directory.
26
+ #
27
+ # @param name [ String ] the name of the configuration file
28
+ #
29
+ # @return [ String ] the full path to the configuration file
2
30
  def xdg_config_filename(name)
3
- if xdg = ENV['XDG_CONFIG_HOME'].full?
4
- File.join(xdg, name)
5
- else
6
- File.join(ENV.fetch('HOME'), '.config', name)
7
- end
31
+ xdg_config_home + name
8
32
  end
9
33
 
10
34
  memoize method:
35
+ # The xdg_config method retrieves configuration data from a file following
36
+ # the XDG Base Directory specification.
37
+ #
38
+ # It checks for the existence of a configuration file using the
39
+ # xdg_config_filename method and returns its contents if found. If the file
40
+ # does not exist, it returns the provided default value instead.
41
+ #
42
+ # @param name [ String ] the name of the configuration file to retrieve
43
+ # @param default [ Object ] the default value to return if the configuration file is not found
44
+ #
45
+ # @return [ String ] the content of the configuration file or the default value
11
46
  def xdg_config(name, default)
12
47
  if File.exist?(xdg_config_filename(name))
13
48
  File.read(xdg_config_filename(name))
@@ -1,6 +1,6 @@
1
1
  class GemHadar
2
2
  # GemHadar version
3
- VERSION = '1.25.0'
3
+ VERSION = '1.27.0'
4
4
  VERSION_ARRAY = VERSION.split('.').map(&:to_i) # :nodoc:
5
5
  VERSION_MAJOR = VERSION_ARRAY[0] # :nodoc:
6
6
  VERSION_MINOR = VERSION_ARRAY[1] # :nodoc: