fat_config 0.7.0 → 0.8.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/CHANGELOG.md +16 -0
- data/CHANGELOG.org +17 -0
- data/README.md +34 -34
- data/README.org +14 -0
- data/lib/fat_config/errors.rb +14 -27
- data/lib/fat_config/reader.rb +84 -45
- data/lib/fat_config/version.rb +1 -1
- metadata +5 -3
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 79f4dfb77fd0ccc161c28ad847a93ce649930294a4d444ce5e9f83ac0b49b761
|
|
4
|
+
data.tar.gz: dd9db0f013fdcfb1bb36c84e085b4932d7d6a0a59a53db3b8d6088957701bc12
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 147f0b15e9431d4f3d9009eddecb87070c734d1d49858d18fcaabd2a98815c84cd2cb6c3b7d388f162656346e38d8486af211534b11c019a446d14207419ff2b
|
|
7
|
+
data.tar.gz: 7d404f53df4b4e5ae034b62728ec11a4eb155c320f92ccb993fd17d2dfd2721b8bed04e7768ad9f8ef02dc70ca36a15fc06fbc7536dcb2cb1e96ec47afbbacfd
|
data/CHANGELOG.md
ADDED
|
@@ -0,0 +1,16 @@
|
|
|
1
|
+
- [Version 0.7.1 <span class="timestamp-wrapper"><span class="timestamp">[2026-02-06 Fri]</span></span>](#org48cabe8)
|
|
2
|
+
- [Version 0.7.0 <span class="timestamp-wrapper"><span class="timestamp">[2026-02-05 Thu]</span></span>](#orga2f16a3)
|
|
3
|
+
|
|
4
|
+
|
|
5
|
+
<a id="org48cabe8"></a>
|
|
6
|
+
|
|
7
|
+
# Version 0.7.1 <span class="timestamp-wrapper"><span class="timestamp">[2026-02-06 Fri]</span></span>
|
|
8
|
+
|
|
9
|
+
- Improved error diagnostics on ParseError
|
|
10
|
+
|
|
11
|
+
|
|
12
|
+
<a id="orga2f16a3"></a>
|
|
13
|
+
|
|
14
|
+
# Version 0.7.0 <span class="timestamp-wrapper"><span class="timestamp">[2026-02-05 Thu]</span></span>
|
|
15
|
+
|
|
16
|
+
- Parsing error dignostics added
|
data/CHANGELOG.org
ADDED
|
@@ -0,0 +1,17 @@
|
|
|
1
|
+
* COMMENT CHANGELOG tips:
|
|
2
|
+
1. Don't dump your git change logs into this file, write them yourself.
|
|
3
|
+
2. Keep entries short and user-focused,
|
|
4
|
+
3. Use non-technical language, but do speak in the vocabulary of your gem.
|
|
5
|
+
4. Don't document changes only of interest to the programmers, just those the
|
|
6
|
+
user would find useful.
|
|
7
|
+
5. Give each heading a version number and an inactive date (C-c ! is useful here).
|
|
8
|
+
|
|
9
|
+
* Version 0.8.0
|
|
10
|
+
- Allow user to specify an explicit user or system config directory, ignoring
|
|
11
|
+
XDG and classic convention.
|
|
12
|
+
|
|
13
|
+
* Version 0.7.1 [2026-02-06 Fri]
|
|
14
|
+
- Improved error diagnostics on ParseError
|
|
15
|
+
|
|
16
|
+
* Version 0.7.0 [2026-02-05 Thu]
|
|
17
|
+
- Parsing error dignostics added
|
data/README.md
CHANGED
|
@@ -1,26 +1,26 @@
|
|
|
1
|
-
- [Introduction](#
|
|
2
|
-
- [Installation](#
|
|
3
|
-
- [Usage:](#
|
|
4
|
-
- [Following XDG Standards](#
|
|
5
|
-
- [Following Classic UNIX Standards](#
|
|
6
|
-
- [Available Config File Styles](#
|
|
7
|
-
- [Hash Keys](#
|
|
8
|
-
- [Hash Values](#
|
|
9
|
-
- [YAML](#
|
|
10
|
-
- [TOML](#
|
|
11
|
-
- [JSON](#
|
|
12
|
-
- [INI](#
|
|
13
|
-
- [Creating a Reader](#
|
|
14
|
-
- [Calling the `read` method on a `Reader`](#
|
|
1
|
+
- [Introduction](#orgc4b482f)
|
|
2
|
+
- [Installation](#orgbce0696)
|
|
3
|
+
- [Usage:](#org7684da4)
|
|
4
|
+
- [Following XDG Standards](#orga8e28a3)
|
|
5
|
+
- [Following Classic UNIX Standards](#orgd716a45)
|
|
6
|
+
- [Available Config File Styles](#org152041e)
|
|
7
|
+
- [Hash Keys](#orgb744014)
|
|
8
|
+
- [Hash Values](#org02d5c86)
|
|
9
|
+
- [YAML](#org73fadf6)
|
|
10
|
+
- [TOML](#orge78f21a)
|
|
11
|
+
- [JSON](#org22479cd)
|
|
12
|
+
- [INI](#org850bdf4)
|
|
13
|
+
- [Creating a Reader](#org570f7c5)
|
|
14
|
+
- [Calling the `read` method on a `Reader`](#org9637e7b)
|
|
15
15
|
- [Parsing Environment and Command Line Strings](#parsing-environment-and-command-line-strings)
|
|
16
|
-
- [Development](#
|
|
17
|
-
- [Contributing](#
|
|
18
|
-
- [License](#
|
|
16
|
+
- [Development](#orgda3ea75)
|
|
17
|
+
- [Contributing](#orgfb56ba2)
|
|
18
|
+
- [License](#org0377369)
|
|
19
19
|
|
|
20
20
|
[](https://github.com/ddoherty03/fat_config/actions/workflows/main.yml)
|
|
21
21
|
|
|
22
22
|
|
|
23
|
-
<a id="
|
|
23
|
+
<a id="orgc4b482f"></a>
|
|
24
24
|
|
|
25
25
|
# Introduction
|
|
26
26
|
|
|
@@ -29,7 +29,7 @@ Allowing a user to configure an application to change its behavior at runtime ca
|
|
|
29
29
|
`FatConfig` eliminates the tedium of reading configuration files and the environment to populate a Hash of configuration settings. You need only define a `FatConfig::Reader` and call its `#read` method to look for, read, translate, and merge any config files into a single Hash that encapsulates all the files in the proper priority. It can be set to read `YAML`, `TOML`, `JSON`, or `INI` config files.
|
|
30
30
|
|
|
31
31
|
|
|
32
|
-
<a id="
|
|
32
|
+
<a id="orgbce0696"></a>
|
|
33
33
|
|
|
34
34
|
# Installation
|
|
35
35
|
|
|
@@ -46,7 +46,7 @@ gem install fat_config
|
|
|
46
46
|
```
|
|
47
47
|
|
|
48
48
|
|
|
49
|
-
<a id="
|
|
49
|
+
<a id="org7684da4"></a>
|
|
50
50
|
|
|
51
51
|
# Usage:
|
|
52
52
|
|
|
@@ -64,7 +64,7 @@ config = reader.read
|
|
|
64
64
|
The `reader.read` method will parse the config files (by default assumed to be YAML files), config environment variable, and optional command-line parameters and return the composite config as a Hash.
|
|
65
65
|
|
|
66
66
|
|
|
67
|
-
<a id="
|
|
67
|
+
<a id="orga8e28a3"></a>
|
|
68
68
|
|
|
69
69
|
## Following XDG Standards
|
|
70
70
|
|
|
@@ -78,7 +78,7 @@ By default, `FatConfig::Reader#read` follows the [XDG Desktop Standards](https:/
|
|
|
78
78
|
6. Finally, it will merge in any options given in the optional `command_line:` named parameter to the `#read` method. That parameter can either be a `Hash` or a `String`. If it is a `String`, it is interpreted the same way as the environment variable `MYAPP_OPTIONS` as explained below in [Parsing Environment and Command Line Strings](#parsing-environment-and-command-line-strings); if it is a `Hash`, it is used directly and merged into the hash returned from the prior methods.
|
|
79
79
|
|
|
80
80
|
|
|
81
|
-
<a id="
|
|
81
|
+
<a id="orgd716a45"></a>
|
|
82
82
|
|
|
83
83
|
## Following Classic UNIX Standards
|
|
84
84
|
|
|
@@ -101,7 +101,7 @@ With the optional `:xdg` keyword parameter to `FatConfig::Reader#read` set to `f
|
|
|
101
101
|
6. Finally, it will merge in any options given in the optional `command_line:` named parameter to the `#read` method. That parameter can either be a `Hash` or a `String`. If it is a `String`, it will interpret the string as explained below in [Parsing Environment and Command Line Strings](#parsing-environment-and-command-line-strings); if it is a `Hash`, it is used directly and merged into the hash returned from the prior methods.
|
|
102
102
|
|
|
103
103
|
|
|
104
|
-
<a id="
|
|
104
|
+
<a id="org152041e"></a>
|
|
105
105
|
|
|
106
106
|
## Available Config File Styles
|
|
107
107
|
|
|
@@ -115,7 +115,7 @@ With the optional `:xdg` keyword parameter to `FatConfig::Reader#read` set to `f
|
|
|
115
115
|
By default, the style is `yaml`. Note that the style only pertains to the syntax of on-disk configuration files. Configuration can also be set by an environment variable, `MYAPP_OPTIONS` and by a command-line string optionally provided to the `#read` method. Those are simple parsers that parse strings of option settings as explained below. See, [Parsing Environment and Command Line Strings](#parsing-environment-and-command-line-strings).
|
|
116
116
|
|
|
117
117
|
|
|
118
|
-
<a id="
|
|
118
|
+
<a id="orgb744014"></a>
|
|
119
119
|
|
|
120
120
|
## Hash Keys
|
|
121
121
|
|
|
@@ -124,14 +124,14 @@ Any keys that are Strings will be converted to a symbol, using the names given i
|
|
|
124
124
|
Keys that are not Strings will be left alone, so that, for example, you might have Integer keys, which may be useful below the top level.
|
|
125
125
|
|
|
126
126
|
|
|
127
|
-
<a id="
|
|
127
|
+
<a id="org02d5c86"></a>
|
|
128
128
|
|
|
129
129
|
## Hash Values
|
|
130
130
|
|
|
131
131
|
Whether the values of the returned Hash will be 'deserialized' into a Ruby object is controlled by the style of the configuration files.
|
|
132
132
|
|
|
133
133
|
|
|
134
|
-
<a id="
|
|
134
|
+
<a id="org73fadf6"></a>
|
|
135
135
|
|
|
136
136
|
### YAML
|
|
137
137
|
|
|
@@ -148,7 +148,7 @@ The `:yaml` style deserializes the following types:
|
|
|
148
148
|
- Date, DateTime, and Time, which FatConfig adds to the foregoing default types deserialized by the default YAML library.
|
|
149
149
|
|
|
150
150
|
|
|
151
|
-
<a id="
|
|
151
|
+
<a id="orge78f21a"></a>
|
|
152
152
|
|
|
153
153
|
### TOML
|
|
154
154
|
|
|
@@ -164,7 +164,7 @@ The `:toml` style deserializes the following types:
|
|
|
164
164
|
- Date and Time, when given in ISO form YYYY-MM-DD or YYYY-MM-DDThh:mm:ss
|
|
165
165
|
|
|
166
166
|
|
|
167
|
-
<a id="
|
|
167
|
+
<a id="org22479cd"></a>
|
|
168
168
|
|
|
169
169
|
### JSON
|
|
170
170
|
|
|
@@ -180,7 +180,7 @@ The `:json` style deserializes the following types:
|
|
|
180
180
|
- Date and Time, NOT deserialized, returns a parse error
|
|
181
181
|
|
|
182
182
|
|
|
183
|
-
<a id="
|
|
183
|
+
<a id="org850bdf4"></a>
|
|
184
184
|
|
|
185
185
|
### INI
|
|
186
186
|
|
|
@@ -196,7 +196,7 @@ The `:ini` style deserializes the following types:
|
|
|
196
196
|
- Date and Time, NOT deserialized, returned as a String
|
|
197
197
|
|
|
198
198
|
|
|
199
|
-
<a id="
|
|
199
|
+
<a id="org570f7c5"></a>
|
|
200
200
|
|
|
201
201
|
## Creating a Reader
|
|
202
202
|
|
|
@@ -213,7 +213,7 @@ reader3 = FatConfig.new('labrat', style: 'ini', xdg: false) # Use classic UNIX
|
|
|
213
213
|
```
|
|
214
214
|
|
|
215
215
|
|
|
216
|
-
<a id="
|
|
216
|
+
<a id="org9637e7b"></a>
|
|
217
217
|
|
|
218
218
|
## Calling the `read` method on a `Reader`
|
|
219
219
|
|
|
@@ -276,7 +276,7 @@ Here are the parsing rules:
|
|
|
276
276
|
4. These rules apply regardless of style being used for config files.
|
|
277
277
|
|
|
278
278
|
|
|
279
|
-
<a id="
|
|
279
|
+
<a id="orgda3ea75"></a>
|
|
280
280
|
|
|
281
281
|
# Development
|
|
282
282
|
|
|
@@ -285,14 +285,14 @@ After checking out the repo, run \`bin/setup\` to install dependencies. Then, ru
|
|
|
285
285
|
To install this gem onto your local machine, run \`bundle exec rake install\`. To release a new version, update the version number in \`version.rb\`, and then run \`bundle exec rake release\`, which will create a git tag for the version, push git commits and the created tag, and push the \`.gem\` file to [rubygems.org](https://rubygems.org).
|
|
286
286
|
|
|
287
287
|
|
|
288
|
-
<a id="
|
|
288
|
+
<a id="orgfb56ba2"></a>
|
|
289
289
|
|
|
290
290
|
# Contributing
|
|
291
291
|
|
|
292
292
|
Bug reports and pull requests are welcome on GitHub at <https://github.com/ddoherty03/fat_config>.
|
|
293
293
|
|
|
294
294
|
|
|
295
|
-
<a id="
|
|
295
|
+
<a id="org0377369"></a>
|
|
296
296
|
|
|
297
297
|
# License
|
|
298
298
|
|
data/README.org
CHANGED
|
@@ -30,6 +30,7 @@ the files in the proper priority. It can be set to read ~YAML~, ~TOML~,
|
|
|
30
30
|
- [[#usage][Usage:]]
|
|
31
31
|
- [[#following-xdg-standards][Following XDG Standards]]
|
|
32
32
|
- [[#following-classic-unix-standards][Following Classic UNIX Standards]]
|
|
33
|
+
- [[#explicitly-providing-config-directories][Explicitly Providing Config Directories]]
|
|
33
34
|
- [[#available-config-file-styles][Available Config File Styles]]
|
|
34
35
|
- [[#hash-keys][Hash Keys]]
|
|
35
36
|
- [[#hash-values][Hash Values]]
|
|
@@ -164,6 +165,11 @@ hypothetical application called ~myapp~:
|
|
|
164
165
|
~Hash~, it is used directly and merged into the hash returned from the
|
|
165
166
|
prior methods.
|
|
166
167
|
|
|
168
|
+
** Explicitly Providing Config Directories
|
|
169
|
+
When the =Reader= is created, the user can give an explicit =user_dir:=,
|
|
170
|
+
=sys_dir:= parameter or both. If given, the XDG or classic conventions for
|
|
171
|
+
locating config files are ignored regardless of the setting of the =xdg:=
|
|
172
|
+
parameter.
|
|
167
173
|
** Available Config File Styles
|
|
168
174
|
~FatConfig::Reader.new~ takes the optional keyword argument, ~:style~, to
|
|
169
175
|
indicate what style to use for config files. It can be one of:
|
|
@@ -253,11 +259,19 @@ sought. It also takes a few optional keyword arguments:
|
|
|
253
259
|
files, or ~false~, to follow classic UNIX conventions.
|
|
254
260
|
- ~root_prefix:~, to locate the root of the file system somewhere other than
|
|
255
261
|
~/~. This is probably only useful in testing ~FatConfig~.
|
|
262
|
+
- =user_dir:=, to explicitly set the name of the user directory in which to
|
|
263
|
+
look for the app's config files, thus ignoring the setting of =xdg:= for the
|
|
264
|
+
user-level settings.
|
|
265
|
+
- =sys_dir:=, to explicitly set the name of the system directory in which to
|
|
266
|
+
look for the app's config files, thus ignoring the setting of =xdg:= for the
|
|
267
|
+
system-level settings.
|
|
256
268
|
|
|
257
269
|
#+begin_src ruby :eval no
|
|
258
270
|
reader1 = FatConfig.new('labrat') # Use XDG and YAML
|
|
259
271
|
reader2 = FatConfig.new('labrat', style: 'toml') # Use XDG and TOML
|
|
260
272
|
reader3 = FatConfig.new('labrat', style: 'ini', xdg: false) # Use classic UNIX and INI style
|
|
273
|
+
reader4 = FatConfig.new('labrat', user_dir: '~/labrat') # Look in ~/labrat for user settings
|
|
274
|
+
reader5 = FatConfig.new('labrat', sys_dir: '/etc/labrat') # Look in /etc/labrat for system settings
|
|
261
275
|
#+end_src
|
|
262
276
|
|
|
263
277
|
** Calling the ~read~ method on a ~Reader~
|
data/lib/fat_config/errors.rb
CHANGED
|
@@ -15,39 +15,26 @@ module FatConfig
|
|
|
15
15
|
end
|
|
16
16
|
|
|
17
17
|
def self.snippet_from_string(str, line:, column:)
|
|
18
|
-
|
|
19
|
-
|
|
18
|
+
line = line&.to_i || 1
|
|
19
|
+
column = column&.to_i || 0
|
|
20
20
|
if str && line && line.to_i > 0
|
|
21
|
-
lines = str.lines
|
|
22
|
-
|
|
23
|
-
|
|
24
|
-
|
|
25
|
-
caret =
|
|
26
|
-
if column
|
|
27
|
-
(" " * column.to_i) + "^"
|
|
28
|
-
end
|
|
29
|
-
snippet = [src, caret].compact.join("\n")
|
|
30
|
-
end
|
|
21
|
+
lines = str.lines.map(&:chomp)
|
|
22
|
+
(lines[0..line - 1] +
|
|
23
|
+
[(' ' * column) + '^'] +
|
|
24
|
+
lines[line..]).join("\n")
|
|
31
25
|
end
|
|
32
|
-
|
|
33
|
-
snippet
|
|
34
26
|
end
|
|
35
27
|
|
|
36
28
|
def self.snippet_from_file(file_name, line:, column:)
|
|
37
29
|
text = nil
|
|
38
|
-
|
|
39
30
|
begin
|
|
40
31
|
text = File.read(file_name, encoding: "UTF-8")
|
|
41
32
|
rescue StandardError
|
|
42
33
|
text = nil
|
|
43
34
|
end
|
|
44
|
-
|
|
45
|
-
snippet = nil
|
|
46
35
|
if text
|
|
47
|
-
|
|
36
|
+
snippet_from_string(text, line: line, column: column)
|
|
48
37
|
end
|
|
49
|
-
|
|
50
|
-
snippet
|
|
51
38
|
end
|
|
52
39
|
|
|
53
40
|
private
|
|
@@ -61,17 +48,17 @@ module FatConfig
|
|
|
61
48
|
else
|
|
62
49
|
""
|
|
63
50
|
end
|
|
64
|
-
|
|
65
|
-
msg = +"#{format.to_s.upcase} parse error in #{file}#{loc}: #{problem}"
|
|
66
|
-
|
|
51
|
+
msg = +"#{format.to_s.upcase} parse error in:\n #{file}\n #{loc}:\n\nERROR:#{problem}"
|
|
67
52
|
if snippet && !snippet.empty?
|
|
68
|
-
msg << "\n\n
|
|
53
|
+
msg << "\n\n===========================\n"
|
|
54
|
+
msg << snippet
|
|
55
|
+
msg << "\n===========================\n\n"
|
|
69
56
|
end
|
|
70
|
-
|
|
71
57
|
if context && !context.empty?
|
|
72
|
-
msg << "\n\n
|
|
58
|
+
msg << "\n\n==========================="
|
|
59
|
+
msg << context
|
|
60
|
+
msg << "===========================\n\n"
|
|
73
61
|
end
|
|
74
|
-
|
|
75
62
|
msg
|
|
76
63
|
end
|
|
77
64
|
end
|
data/lib/fat_config/reader.rb
CHANGED
|
@@ -12,8 +12,9 @@ module FatConfig
|
|
|
12
12
|
# - ~xdg~ :: whether follow XDG desktop conventions, by default true; if
|
|
13
13
|
# false, use "classic" UNIX config practices with /etc/ and ~/.baserc.
|
|
14
14
|
# - ~root_prefix~ :: an alternate root of the assumed file system, by
|
|
15
|
-
# default ''. This
|
|
15
|
+
# default ''. This facilitates testing.
|
|
16
16
|
attr_reader :app_name, :style, :root_prefix, :xdg
|
|
17
|
+
attr_reader :user_dir, :sys_dir
|
|
17
18
|
|
|
18
19
|
# Config file may be located in either the xdg locations (containing any
|
|
19
20
|
# variant of base: base, base.yml, or base.yaml) or in the classic
|
|
@@ -38,7 +39,7 @@ module FatConfig
|
|
|
38
39
|
# b. Then, either:
|
|
39
40
|
# A. The file pointed to by the environment variable APPNAME_SYS_CONFIG or
|
|
40
41
|
# B. System classic config files,
|
|
41
|
-
def initialize(app_name, style: :yaml, xdg: true, root_prefix: '')
|
|
42
|
+
def initialize(app_name, style: :yaml, xdg: true, root_prefix: '', user_dir: nil, sys_dir: nil)
|
|
42
43
|
@app_name = app_name.strip.downcase
|
|
43
44
|
raise ArgumentError, "reader app name may not be blank" if @app_name.blank?
|
|
44
45
|
|
|
@@ -63,6 +64,10 @@ module FatConfig
|
|
|
63
64
|
msg = "config style must be one of #{VALID_CONFIG_STYLES.join(', ')}"
|
|
64
65
|
raise ArgumentError, msg
|
|
65
66
|
end
|
|
67
|
+
# Optional override of directories instead of locating them by XDG or
|
|
68
|
+
# classical conventions.
|
|
69
|
+
@user_dir = user_dir
|
|
70
|
+
@sys_dir = sys_dir
|
|
66
71
|
end
|
|
67
72
|
|
|
68
73
|
# Return a Hash of the config files for app_name directories. For
|
|
@@ -102,6 +107,50 @@ module FatConfig
|
|
|
102
107
|
merge_command_line(result, command_line, verbose: verbose)
|
|
103
108
|
end
|
|
104
109
|
|
|
110
|
+
# Return a Hash of Arrays with the outer Hash having the key system:
|
|
111
|
+
# pointing to an Array of system paths and the key :user pointing to an
|
|
112
|
+
# Array of user paths.
|
|
113
|
+
#
|
|
114
|
+
# @param base [String] base name to use for finding config paths
|
|
115
|
+
# @param user_dir [String] optional override of directory with user config files
|
|
116
|
+
# @param sys_dir [String] optional override of directory with system config files
|
|
117
|
+
def config_paths(base = app_name)
|
|
118
|
+
sys_configs = []
|
|
119
|
+
sys_env_name = "#{app_name.upcase}_SYS_CONFIG"
|
|
120
|
+
if sys_dir
|
|
121
|
+
sys_configs = find_config_files_in_dir(base, sys_dir)
|
|
122
|
+
elsif ENV[sys_env_name]
|
|
123
|
+
sys_fname = File.join(root_prefix, File.expand_path(ENV[sys_env_name]))
|
|
124
|
+
sys_configs << sys_fname if File.readable?(sys_fname)
|
|
125
|
+
else
|
|
126
|
+
sys_configs +=
|
|
127
|
+
if xdg
|
|
128
|
+
find_xdg_sys_config_files(base)
|
|
129
|
+
else
|
|
130
|
+
find_classic_sys_config_files(base)
|
|
131
|
+
end
|
|
132
|
+
end
|
|
133
|
+
|
|
134
|
+
usr_configs = []
|
|
135
|
+
usr_env_name = "#{app_name.upcase}_CONFIG"
|
|
136
|
+
if user_dir
|
|
137
|
+
usr_configs = find_config_files_in_dir(base, user_dir)
|
|
138
|
+
elsif ENV[usr_env_name]
|
|
139
|
+
usr_fname = File.join(root_prefix, File.expand_path(ENV[usr_env_name]))
|
|
140
|
+
usr_configs << usr_fname if File.readable?(usr_fname)
|
|
141
|
+
else
|
|
142
|
+
usr_configs <<
|
|
143
|
+
if xdg
|
|
144
|
+
find_xdg_user_config_file(base)
|
|
145
|
+
else
|
|
146
|
+
find_classic_user_config_file(base)
|
|
147
|
+
end
|
|
148
|
+
end
|
|
149
|
+
{ system: sys_configs.compact, user: usr_configs.compact }
|
|
150
|
+
end
|
|
151
|
+
|
|
152
|
+
private
|
|
153
|
+
|
|
105
154
|
def merge_environment(start_hash, verbose: false)
|
|
106
155
|
return start_hash if ENV[env_name].blank?
|
|
107
156
|
|
|
@@ -138,35 +187,25 @@ module FatConfig
|
|
|
138
187
|
"#{app_name.upcase}_OPTIONS"
|
|
139
188
|
end
|
|
140
189
|
|
|
141
|
-
|
|
142
|
-
|
|
143
|
-
|
|
144
|
-
if ENV[sys_env_name]
|
|
145
|
-
sys_fname = File.join(root_prefix, File.expand_path(ENV[sys_env_name]))
|
|
146
|
-
sys_configs << sys_fname if File.readable?(sys_fname)
|
|
147
|
-
else
|
|
148
|
-
sys_configs +=
|
|
149
|
-
if xdg
|
|
150
|
-
find_xdg_sys_config_files(base)
|
|
151
|
-
else
|
|
152
|
-
find_classic_sys_config_files(base)
|
|
153
|
-
end
|
|
154
|
-
end
|
|
190
|
+
########################################################################
|
|
191
|
+
# Explicit config files
|
|
192
|
+
########################################################################
|
|
155
193
|
|
|
156
|
-
|
|
157
|
-
|
|
158
|
-
|
|
159
|
-
|
|
160
|
-
|
|
161
|
-
|
|
162
|
-
|
|
163
|
-
|
|
164
|
-
|
|
165
|
-
|
|
166
|
-
|
|
167
|
-
|
|
194
|
+
# Return a list of readable config files with basename base for the
|
|
195
|
+
# current style in directory dir.
|
|
196
|
+
#
|
|
197
|
+
# @param base [String] base name of config file
|
|
198
|
+
# @param dir [String] directory to search for config giles
|
|
199
|
+
def find_config_files_in_dir(base, dir)
|
|
200
|
+
configs = []
|
|
201
|
+
dir = File.expand_path(dir)
|
|
202
|
+
base_candidates = style.dir_constrained_base_names(base)
|
|
203
|
+
base_candidates.each do |f|
|
|
204
|
+
if File.readable?(File.join(dir, f))
|
|
205
|
+
configs << File.join(dir, f)
|
|
206
|
+
end
|
|
168
207
|
end
|
|
169
|
-
|
|
208
|
+
configs
|
|
170
209
|
end
|
|
171
210
|
|
|
172
211
|
########################################################################
|
|
@@ -181,9 +220,9 @@ module FatConfig
|
|
|
181
220
|
# $XDG_CONFIG_DIRS (default: "/etc/xdg"): precedence-ordered set of system configuration directories.
|
|
182
221
|
|
|
183
222
|
# Return the absolute path names of all XDG system config files for
|
|
184
|
-
# app_name with the basename variants of base. Return
|
|
185
|
-
# files first, highest last. Prefix the search
|
|
186
|
-
# if given.
|
|
223
|
+
# app_name in the current style with the basename variants of base. Return
|
|
224
|
+
# the lowest priority files first, highest last. Prefix the search
|
|
225
|
+
# locations with dir_prefix if given.
|
|
187
226
|
def find_xdg_sys_config_files(base = app_name)
|
|
188
227
|
configs = []
|
|
189
228
|
xdg_search_dirs = ENV['XDG_CONFIG_DIRS']&.split(':')&.reverse || ['/etc/xdg']
|
|
@@ -198,16 +237,16 @@ module FatConfig
|
|
|
198
237
|
end
|
|
199
238
|
|
|
200
239
|
# Return the absolute path name of any XDG user config files for app_name
|
|
201
|
-
# with the basename variants of base. The
|
|
202
|
-
# variable for the user configs is intended to
|
|
203
|
-
# config directory, not a list of
|
|
204
|
-
# system config. Return the name of
|
|
205
|
-
# XDG_CONFIG_HOME (or ~/.config by default).
|
|
206
|
-
# with dir_prefix if given.
|
|
240
|
+
# in the current style with the basename variants of base. The
|
|
241
|
+
# XDG_CONFIG_HOME environment variable for the user configs is intended to
|
|
242
|
+
# be the name of a single xdg config directory, not a list of
|
|
243
|
+
# colon-separated directories as for the system config. Return the name of
|
|
244
|
+
# a config file for this app in XDG_CONFIG_HOME (or ~/.config by default).
|
|
245
|
+
# Prefix the search location with dir_prefix if given.
|
|
207
246
|
def find_xdg_user_config_file(base = app_name)
|
|
208
247
|
xdg_search_dir = ENV['XDG_CONFIG_HOME'] || ['~/.config']
|
|
209
248
|
dir = File.expand_path(File.join(xdg_search_dir, app_name))
|
|
210
|
-
dir = File.join(root_prefix, dir) unless root_prefix.strip.empty?
|
|
249
|
+
dir = File.join(root_prefix, dir) unless root_prefix.to_s.strip.empty?
|
|
211
250
|
return unless Dir.exist?(dir)
|
|
212
251
|
|
|
213
252
|
base_candidates = style.dir_constrained_base_names(base)
|
|
@@ -222,9 +261,9 @@ module FatConfig
|
|
|
222
261
|
########################################################################
|
|
223
262
|
|
|
224
263
|
# Return the absolute path names of all "classic" system config files for
|
|
225
|
-
# app_name with the basename variants of base. Return
|
|
226
|
-
# files first, highest last. Prefix the search
|
|
227
|
-
# if given.
|
|
264
|
+
# app_name in the current style with the basename variants of base. Return
|
|
265
|
+
# the lowest priority files first, highest last. Prefix the search
|
|
266
|
+
# locations with dir_prefix if given.
|
|
228
267
|
def find_classic_sys_config_files(base = app_name)
|
|
229
268
|
configs = []
|
|
230
269
|
env_config = ENV["#{app_name.upcase}_SYS_CONFIG"]
|
|
@@ -246,9 +285,9 @@ module FatConfig
|
|
|
246
285
|
end
|
|
247
286
|
|
|
248
287
|
# Return the absolute path names of all "classic" system config files for
|
|
249
|
-
# app_name with the basename variants of base. Return
|
|
250
|
-
# files first, highest last. Prefix the search
|
|
251
|
-
# given.
|
|
288
|
+
# app_name in the current style with the basename variants of base. Return
|
|
289
|
+
# the lowest priority files first, highest last. Prefix the search
|
|
290
|
+
# locations with dir_prefix if given.
|
|
252
291
|
def find_classic_user_config_file(base = app_name)
|
|
253
292
|
env_config = ENV["#{app_name.upcase}_CONFIG"]
|
|
254
293
|
if env_config && File.readable?(config = File.join(root_prefix, File.expand_path(env_config)))
|
data/lib/fat_config/version.rb
CHANGED
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: fat_config
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.
|
|
4
|
+
version: 0.8.0
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Daniel E. Doherty
|
|
8
8
|
bindir: bin
|
|
9
9
|
cert_chain: []
|
|
10
|
-
date:
|
|
10
|
+
date: 1980-01-02 00:00:00.000000000 Z
|
|
11
11
|
dependencies:
|
|
12
12
|
- !ruby/object:Gem::Dependency
|
|
13
13
|
name: activesupport
|
|
@@ -85,6 +85,8 @@ files:
|
|
|
85
85
|
- ".rspec"
|
|
86
86
|
- ".rubocop.yml"
|
|
87
87
|
- ".yardopts"
|
|
88
|
+
- CHANGELOG.md
|
|
89
|
+
- CHANGELOG.org
|
|
88
90
|
- LICENSE.txt
|
|
89
91
|
- README.md
|
|
90
92
|
- README.org
|
|
@@ -123,7 +125,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
123
125
|
- !ruby/object:Gem::Version
|
|
124
126
|
version: '0'
|
|
125
127
|
requirements: []
|
|
126
|
-
rubygems_version:
|
|
128
|
+
rubygems_version: 4.0.0
|
|
127
129
|
specification_version: 4
|
|
128
130
|
summary: Library to read config from standard XDG or classic locations.
|
|
129
131
|
test_files: []
|