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.
- checksums.yaml +4 -4
- data/README.md +479 -10
- data/VERSION +1 -1
- data/gem_hadar.gemspec +3 -3
- data/lib/gem_hadar/prompt_template.rb +37 -0
- data/lib/gem_hadar/setup.rb +4 -0
- data/lib/gem_hadar/template_compiler.rb +29 -0
- data/lib/gem_hadar/utils.rb +40 -5
- data/lib/gem_hadar/version.rb +1 -1
- data/lib/gem_hadar.rb +508 -53
- metadata +3 -3
data/lib/gem_hadar/utils.rb
CHANGED
@@ -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
|
-
|
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))
|