config_files 0.2.1 → 0.2.2
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/.github/workflows/ci.yml +17 -0
- data/CHANGELOG.md +12 -0
- data/MULTI_RUBY_SETUP.md +3 -1
- data/README.md +15 -1
- data/config_files.gemspec +1 -1
- data/lib/config_files/loader_factory.rb +18 -3
- data/lib/config_files/loaders/json.rb +1 -1
- data/lib/config_files/loaders/yaml.rb +10 -1
- data/lib/config_files/version.rb +1 -1
- data/lib/config_files.rb +23 -3
- data/scripts/test_docker.sh +6 -1
- data/scripts/test_multiple_rubies.sh +6 -1
- data/test/load_robustness_test.rb +87 -0
- data/test/stray_files_test.rb +72 -0
- metadata +5 -9
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: 2710dea587c6d0181879261bc6c61afbc7962671b159e56b98240813f7852d7d
|
|
4
|
+
data.tar.gz: 4cc06b016085761a6e7cc19211c9f2b94636e667fe1306a82a8e6215d14364b8
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: f7bbda8a71c74af5c01460c5d8d7d48d3dbc27b841d6fe88a72b65ddabedcaab0a567f977fdf571cb20af597ebad0c9c83691ddd35fa49e47b8bd6448bd1a049
|
|
7
|
+
data.tar.gz: 4036e3a86e806977a0ac70a6f306e508ce204e68cdf685c73ab5f853db2f2202f412add028d9fbd44ca8dbfe1f55724ecd31c95dd4ac155a4b9e80efd38efac2
|
data/.github/workflows/ci.yml
CHANGED
|
@@ -24,6 +24,10 @@ jobs:
|
|
|
24
24
|
- '~> 7.0.0'
|
|
25
25
|
- '~> 7.1.0'
|
|
26
26
|
- '~> 7.2.0'
|
|
27
|
+
- '~> 8.0.0'
|
|
28
|
+
- '~> 8.1.0'
|
|
29
|
+
# Unpinned: newest release the Ruby allows, so a new major (9.x) is tested on arrival
|
|
30
|
+
- '>= 6.1'
|
|
27
31
|
exclude:
|
|
28
32
|
# ActiveSupport 7.1+ requires Ruby 3.1+
|
|
29
33
|
- ruby-version: '2.7'
|
|
@@ -34,6 +38,19 @@ jobs:
|
|
|
34
38
|
activesupport-version: '~> 7.2.0'
|
|
35
39
|
- ruby-version: '3.0'
|
|
36
40
|
activesupport-version: '~> 7.2.0'
|
|
41
|
+
# ActiveSupport 8.0+ requires Ruby 3.2+
|
|
42
|
+
- ruby-version: '2.7'
|
|
43
|
+
activesupport-version: '~> 8.0.0'
|
|
44
|
+
- ruby-version: '3.0'
|
|
45
|
+
activesupport-version: '~> 8.0.0'
|
|
46
|
+
- ruby-version: '3.1'
|
|
47
|
+
activesupport-version: '~> 8.0.0'
|
|
48
|
+
- ruby-version: '2.7'
|
|
49
|
+
activesupport-version: '~> 8.1.0'
|
|
50
|
+
- ruby-version: '3.0'
|
|
51
|
+
activesupport-version: '~> 8.1.0'
|
|
52
|
+
- ruby-version: '3.1'
|
|
53
|
+
activesupport-version: '~> 8.1.0'
|
|
37
54
|
|
|
38
55
|
env:
|
|
39
56
|
ACTIVESUPPORT_VERSION: ${{ matrix.activesupport-version }}
|
data/CHANGELOG.md
CHANGED
|
@@ -5,6 +5,18 @@ All notable changes to this project will be documented in this file.
|
|
|
5
5
|
The format is based on [Keep a Changelog](https://keepachangelog.com/en/1.0.0/),
|
|
6
6
|
and this project adheres to [Semantic Versioning](https://semver.org/spec/v2.0.0.html).
|
|
7
7
|
|
|
8
|
+
## [0.2.2] - 2026-12-01
|
|
9
|
+
|
|
10
|
+
### Changed
|
|
11
|
+
- ActiveSupport dependency is now `>= 6.1` with no upper bound, allowing 8.x (including 8.0.5.2+, which fixes the `safe_constantize` DoS advisory) and future majors. CI covers 8.0, 8.1 and the newest release.
|
|
12
|
+
- README: security note recommending ActiveSupport >= 8.0.5.2 on Ruby 3.2+, and updated file-matching and error-handling docs.
|
|
13
|
+
|
|
14
|
+
### Fixed
|
|
15
|
+
- Stray files beside a config file (`dds.yaml.save`, `dds.yaml~`, `dds.old.yaml`) were loaded as YAML and merged over the real config. Only `<name>.<ext>` files with a registered loader (yaml, yml, json, xml, conf, ini) are loaded now.
|
|
16
|
+
- A config file that loaded as something other than a hash crashed the merge with `undefined method 'to_hash'`. Empty and comment-only files now contribute nothing; a top-level list or scalar raises `ConfigFiles::InvalidConfigError` naming the file.
|
|
17
|
+
- YAML files using anchors/aliases, dates or times failed to load on Ruby 3.1+ (Psych 4 safe loading).
|
|
18
|
+
- JSON loader failed on json 3.x (Ruby 4) because options were passed as a positional hash.
|
|
19
|
+
|
|
8
20
|
## [0.2.1] - 2025-09-27
|
|
9
21
|
|
|
10
22
|
### Fixed
|
data/MULTI_RUBY_SETUP.md
CHANGED
|
@@ -34,7 +34,7 @@ This document summarizes the multi-Ruby version testing setup for the ConfigFile
|
|
|
34
34
|
### ✅ CI/CD Integration
|
|
35
35
|
|
|
36
36
|
#### GitHub Actions (`.github/workflows/ci.yml`)
|
|
37
|
-
- **Matrix testing** across Ruby 2.7-3.4 and ActiveSupport 6.1-
|
|
37
|
+
- **Matrix testing** across Ruby 2.7-3.4 and ActiveSupport 6.1-8.1, plus the newest release in CI
|
|
38
38
|
- **Automatic exclusion** of incompatible combinations
|
|
39
39
|
- **RuboCop linting** integration
|
|
40
40
|
- **Free for open source** projects
|
|
@@ -92,6 +92,8 @@ This document summarizes the multi-Ruby version testing setup for the ConfigFile
|
|
|
92
92
|
|
|
93
93
|
**Total Combinations Tested**: 20 valid combinations (4 incompatible combinations automatically skipped)
|
|
94
94
|
|
|
95
|
+
ActiveSupport 8.0 and 8.1 are also tested; they require Ruby 3.2+ and are skipped on older Rubies. The table above predates them.
|
|
96
|
+
|
|
95
97
|
## 🛠 Key Features
|
|
96
98
|
|
|
97
99
|
### Smart Version Management
|
data/README.md
CHANGED
|
@@ -29,6 +29,18 @@ Or install it:
|
|
|
29
29
|
gem install config_files
|
|
30
30
|
```
|
|
31
31
|
|
|
32
|
+
### Security: ActiveSupport version
|
|
33
|
+
|
|
34
|
+
ActiveSupport releases before 8.0.5.2 are affected by a denial-of-service advisory in `safe_constantize`. config_files supports ActiveSupport 6.1 and later so that older Rubies keep working, which means your bundle may resolve to an affected version.
|
|
35
|
+
|
|
36
|
+
If you are on Ruby 3.2 or later, require a fixed version in your Gemfile:
|
|
37
|
+
|
|
38
|
+
```ruby
|
|
39
|
+
gem 'activesupport', '>= 8.0.5.2'
|
|
40
|
+
```
|
|
41
|
+
|
|
42
|
+
On Ruby 2.7 to 3.1, ActiveSupport 8 is not available; whether to accept the advisory or upgrade Ruby is your call.
|
|
43
|
+
|
|
32
44
|
## Usage
|
|
33
45
|
|
|
34
46
|
```ruby
|
|
@@ -84,7 +96,7 @@ config/
|
|
|
84
96
|
└── app.conf # Other formats
|
|
85
97
|
```
|
|
86
98
|
|
|
87
|
-
|
|
99
|
+
Files named `<name>.<ext>` get merged together when `<ext>` is a supported format: `yaml`, `yml`, `json`, `xml`, `conf` or `ini` (case-insensitive). Anything else beside them, such as `app.yml.save`, `app.yml~` or `app.old.yml`, is ignored. Files are processed alphabetically, so `app.json` loads before `app.yml`.
|
|
88
100
|
|
|
89
101
|
## Static vs Dynamic
|
|
90
102
|
|
|
@@ -200,6 +212,8 @@ end
|
|
|
200
212
|
AppConfig.missing_file # => {} (empty hash)
|
|
201
213
|
```
|
|
202
214
|
|
|
215
|
+
An empty or comment-only file contributes nothing. A file whose top level is not a mapping (a list or a plain value) raises `ConfigFiles::InvalidConfigError` naming the file.
|
|
216
|
+
|
|
203
217
|
## Testing
|
|
204
218
|
|
|
205
219
|
Run the tests:
|
data/config_files.gemspec
CHANGED
|
@@ -22,7 +22,7 @@ Gem::Specification.new do |spec|
|
|
|
22
22
|
spec.license = 'MIT'
|
|
23
23
|
spec.required_ruby_version = '>= 2.7.0'
|
|
24
24
|
|
|
25
|
-
spec.add_dependency 'activesupport', '>= 6.1'
|
|
25
|
+
spec.add_dependency 'activesupport', '>= 6.1'
|
|
26
26
|
spec.add_dependency 'rexml', '~> 3.2'
|
|
27
27
|
spec.metadata['rubygems_mfa_required'] = 'true'
|
|
28
28
|
end
|
|
@@ -6,6 +6,10 @@ module ConfigFiles
|
|
|
6
6
|
def call(file_name, options = { include_default: true })
|
|
7
7
|
new(options).call(file_name)
|
|
8
8
|
end
|
|
9
|
+
|
|
10
|
+
def registered?(file_name, options = { include_default: true })
|
|
11
|
+
new(options).registered?(file_name)
|
|
12
|
+
end
|
|
9
13
|
end
|
|
10
14
|
|
|
11
15
|
private
|
|
@@ -53,9 +57,20 @@ module ConfigFiles
|
|
|
53
57
|
public
|
|
54
58
|
|
|
55
59
|
def call(file_name)
|
|
56
|
-
|
|
57
|
-
|
|
58
|
-
|
|
60
|
+
registered_loader(file_name) || default_loader
|
|
61
|
+
end
|
|
62
|
+
|
|
63
|
+
# True when a loader is registered for the file's extension. The default
|
|
64
|
+
# loader is a fallback for explicit calls and does not count.
|
|
65
|
+
def registered?(file_name)
|
|
66
|
+
!registered_loader(file_name).nil?
|
|
67
|
+
end
|
|
68
|
+
|
|
69
|
+
private
|
|
70
|
+
|
|
71
|
+
def registered_loader(file_name)
|
|
72
|
+
extension = ::File.extname(file_name).strip.downcase[1..]
|
|
73
|
+
loaders.detect { |_, extensions| extensions.include?(extension) }&.first
|
|
59
74
|
end
|
|
60
75
|
end
|
|
61
76
|
end
|
|
@@ -7,7 +7,7 @@ module ConfigFiles
|
|
|
7
7
|
class Json
|
|
8
8
|
class << self
|
|
9
9
|
def call(file_name, object_class: ::Hash)
|
|
10
|
-
::JSON.parse(::File.read(file_name),
|
|
10
|
+
::JSON.parse(::File.read(file_name), object_class: object_class)
|
|
11
11
|
end
|
|
12
12
|
end
|
|
13
13
|
end
|
|
@@ -1,11 +1,20 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
+
require 'date'
|
|
4
|
+
require 'yaml'
|
|
5
|
+
|
|
3
6
|
module ConfigFiles
|
|
4
7
|
module Loaders
|
|
5
8
|
class Yaml
|
|
9
|
+
# Psych 4 (Ruby 3.1+) made load_file safe, which rejects anchors, dates and
|
|
10
|
+
# times that ordinary config files use. safe_load with these options behaves
|
|
11
|
+
# the same on Psych 3.1 and 4.
|
|
12
|
+
PERMITTED_CLASSES = [::Date, ::Time, ::Symbol].freeze
|
|
13
|
+
|
|
6
14
|
class << self
|
|
7
15
|
def call(file_name)
|
|
8
|
-
::YAML.
|
|
16
|
+
::YAML.safe_load(::File.read(file_name), permitted_classes: PERMITTED_CLASSES, aliases: true,
|
|
17
|
+
filename: file_name)
|
|
9
18
|
end
|
|
10
19
|
end
|
|
11
20
|
end
|
data/lib/config_files/version.rb
CHANGED
data/lib/config_files.rb
CHANGED
|
@@ -14,6 +14,10 @@ require 'yaml'
|
|
|
14
14
|
class NoDirectoryEntry < NoMethodError; end
|
|
15
15
|
|
|
16
16
|
module ConfigFiles
|
|
17
|
+
# A config file loaded to something other than a hash (a top-level list or
|
|
18
|
+
# scalar), which cannot be merged with its siblings.
|
|
19
|
+
class InvalidConfigError < StandardError; end
|
|
20
|
+
|
|
17
21
|
class << self
|
|
18
22
|
def included(base)
|
|
19
23
|
base.class_eval do
|
|
@@ -55,8 +59,8 @@ module ConfigFiles
|
|
|
55
59
|
end
|
|
56
60
|
|
|
57
61
|
def merged_hash(file)
|
|
58
|
-
all_config_files(file).inject(::HashWithIndifferentAccess.new) do |master,
|
|
59
|
-
master.deep_merge(
|
|
62
|
+
all_config_files(file).inject(::HashWithIndifferentAccess.new) do |master, path|
|
|
63
|
+
master.deep_merge(load_hash(path))
|
|
60
64
|
end
|
|
61
65
|
end
|
|
62
66
|
|
|
@@ -81,8 +85,24 @@ module ConfigFiles
|
|
|
81
85
|
|
|
82
86
|
private
|
|
83
87
|
|
|
88
|
+
# An empty or comment-only file loads as nil or false and contributes nothing.
|
|
89
|
+
def load_hash(path)
|
|
90
|
+
content = FileFactory.call(path)
|
|
91
|
+
return {} if content.nil? || content == false
|
|
92
|
+
return content if content.is_a?(::Hash)
|
|
93
|
+
|
|
94
|
+
raise InvalidConfigError,
|
|
95
|
+
"#{path} must contain a mapping at the top level, but it loaded as #{content.class}"
|
|
96
|
+
end
|
|
97
|
+
|
|
98
|
+
# Only "<file>.<ext>" where a loader is registered for <ext>. Anything else
|
|
99
|
+
# matching the glob (dds.yaml.save, dds.yaml~, dds.old.yaml) is a stray.
|
|
84
100
|
def directory_listing(directory, file)
|
|
85
|
-
::Dir.glob(::File.join(directory, "#{file}.*")).sort
|
|
101
|
+
::Dir.glob(::File.join(directory, "#{file}.*")).select { |path| config_file?(path, file) }.sort
|
|
102
|
+
end
|
|
103
|
+
|
|
104
|
+
def config_file?(path, file)
|
|
105
|
+
::File.basename(path, ::File.extname(path)) == file.to_s && LoaderFactory.registered?(path)
|
|
86
106
|
end
|
|
87
107
|
|
|
88
108
|
def first_directory(file, key = config_key)
|
data/scripts/test_docker.sh
CHANGED
|
@@ -14,7 +14,7 @@ NC='\033[0m' # No Color
|
|
|
14
14
|
RUBY_VERSIONS=("2.7" "3.0" "3.1" "3.2" "3.3" "3.4")
|
|
15
15
|
|
|
16
16
|
# ActiveSupport versions to test
|
|
17
|
-
ACTIVESUPPORT_VERSIONS=("~> 6.1.0" "~> 7.0.0" "~> 7.1.0" "~> 7.2.0")
|
|
17
|
+
ACTIVESUPPORT_VERSIONS=("~> 6.1.0" "~> 7.0.0" "~> 7.1.0" "~> 7.2.0" "~> 8.0.0" "~> 8.1.0")
|
|
18
18
|
|
|
19
19
|
# Function to test a specific Ruby and ActiveSupport combination
|
|
20
20
|
test_combination() {
|
|
@@ -28,6 +28,11 @@ test_combination() {
|
|
|
28
28
|
echo -e "${YELLOW}Skipping incompatible combination${NC}"
|
|
29
29
|
return 0
|
|
30
30
|
fi
|
|
31
|
+
# ActiveSupport 8.x requires Ruby 3.2+
|
|
32
|
+
if [[ "$ruby_version" =~ ^(2\.|3\.[01]) ]] && [[ "$activesupport_version" =~ 8\. ]]; then
|
|
33
|
+
echo -e "${YELLOW}Skipping incompatible combination${NC}"
|
|
34
|
+
return 0
|
|
35
|
+
fi
|
|
31
36
|
|
|
32
37
|
# Build and run Docker container
|
|
33
38
|
if docker build \
|
|
@@ -16,7 +16,7 @@ NC='\033[0m' # No Color
|
|
|
16
16
|
RUBY_VERSIONS=("2.7.8" "3.0.6" "3.1.4" "3.2.2" "3.3.0" "3.4.1")
|
|
17
17
|
|
|
18
18
|
# ActiveSupport versions to test
|
|
19
|
-
ACTIVESUPPORT_VERSIONS=("~> 6.1.0" "~> 7.0.0" "~> 7.1.0" "~> 7.2.0")
|
|
19
|
+
ACTIVESUPPORT_VERSIONS=("~> 6.1.0" "~> 7.0.0" "~> 7.1.0" "~> 7.2.0" "~> 8.0.0" "~> 8.1.0")
|
|
20
20
|
|
|
21
21
|
# Detect which Ruby version manager is available
|
|
22
22
|
RUBY_MANAGER=""
|
|
@@ -151,6 +151,11 @@ test_combination() {
|
|
|
151
151
|
echo -e "${YELLOW}Skipping incompatible combination${NC}"
|
|
152
152
|
return 0
|
|
153
153
|
fi
|
|
154
|
+
# ActiveSupport 8.x requires Ruby 3.2+
|
|
155
|
+
if [[ "$ruby_version" =~ ^(2\.|3\.[01]) ]] && [[ "$activesupport_version" =~ 8\. ]]; then
|
|
156
|
+
echo -e "${YELLOW}Skipping incompatible combination${NC}"
|
|
157
|
+
return 0
|
|
158
|
+
fi
|
|
154
159
|
|
|
155
160
|
# Create temporary Gemfile
|
|
156
161
|
cat > Gemfile.test << EOF
|
|
@@ -0,0 +1,87 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
$LOAD_PATH.push(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
4
|
+
require 'minitest/autorun'
|
|
5
|
+
require 'config_files'
|
|
6
|
+
require 'fileutils'
|
|
7
|
+
require 'tmpdir'
|
|
8
|
+
|
|
9
|
+
# Sibling files with the same name (dds.yaml beside dds.yml) must merge
|
|
10
|
+
# without crashing, whatever their content.
|
|
11
|
+
class LoadRobustnessTest < Minitest::Test
|
|
12
|
+
def setup
|
|
13
|
+
@dir = Dir.mktmpdir('config_files_robust')
|
|
14
|
+
@klass = Class.new do
|
|
15
|
+
include ConfigFiles
|
|
16
|
+
end
|
|
17
|
+
@klass.config_directories(etc: [@dir])
|
|
18
|
+
@klass.dynamic_config_files(:dds)
|
|
19
|
+
end
|
|
20
|
+
|
|
21
|
+
def teardown
|
|
22
|
+
FileUtils.rm_rf(@dir)
|
|
23
|
+
end
|
|
24
|
+
|
|
25
|
+
def write(name, content)
|
|
26
|
+
File.write(File.join(@dir, name), content)
|
|
27
|
+
end
|
|
28
|
+
|
|
29
|
+
def test_identical_yaml_and_yml_merge
|
|
30
|
+
content = "a: 1\nnested:\n b: 2\n"
|
|
31
|
+
write('dds.yaml', content)
|
|
32
|
+
write('dds.yml', content)
|
|
33
|
+
|
|
34
|
+
assert_equal({ 'a' => 1, 'nested' => { 'b' => 2 } }, @klass.dds.to_hash)
|
|
35
|
+
end
|
|
36
|
+
|
|
37
|
+
def test_different_yaml_and_yml_merge_with_later_file_winning
|
|
38
|
+
write('dds.yaml', "a: 1\nnested:\n b: 2\n c: 3\n")
|
|
39
|
+
write('dds.yml', "a: 2\nnested:\n b: 20\nx: 9\n")
|
|
40
|
+
|
|
41
|
+
assert_equal({ 'a' => 2, 'nested' => { 'b' => 20, 'c' => 3 }, 'x' => 9 }, @klass.dds.to_hash)
|
|
42
|
+
end
|
|
43
|
+
|
|
44
|
+
def test_empty_file_contributes_nothing
|
|
45
|
+
write('dds.yaml', "a: 1\n")
|
|
46
|
+
write('dds.yml', '')
|
|
47
|
+
|
|
48
|
+
assert_equal({ 'a' => 1 }, @klass.dds.to_hash)
|
|
49
|
+
end
|
|
50
|
+
|
|
51
|
+
def test_comment_only_file_contributes_nothing
|
|
52
|
+
write('dds.yaml', "# placeholder\n")
|
|
53
|
+
write('dds.yml', "a: 1\n")
|
|
54
|
+
|
|
55
|
+
assert_equal({ 'a' => 1 }, @klass.dds.to_hash)
|
|
56
|
+
end
|
|
57
|
+
|
|
58
|
+
def test_top_level_list_raises_clear_error
|
|
59
|
+
write('dds.yaml', "a: 1\n")
|
|
60
|
+
write('dds.yml', "- x\n- y\n")
|
|
61
|
+
|
|
62
|
+
error = assert_raises(ConfigFiles::InvalidConfigError) { @klass.dds }
|
|
63
|
+
assert_includes(error.message, 'dds.yml')
|
|
64
|
+
assert_includes(error.message, 'Array')
|
|
65
|
+
end
|
|
66
|
+
|
|
67
|
+
def test_top_level_scalar_raises_clear_error
|
|
68
|
+
write('dds.json', '"just a string"')
|
|
69
|
+
|
|
70
|
+
error = assert_raises(ConfigFiles::InvalidConfigError) { @klass.dds }
|
|
71
|
+
assert_includes(error.message, 'dds.json')
|
|
72
|
+
assert_includes(error.message, 'String')
|
|
73
|
+
end
|
|
74
|
+
|
|
75
|
+
def test_yaml_anchors_and_aliases_load
|
|
76
|
+
write('dds.yaml', "base: &base\n host: h\nprod:\n <<: *base\n port: 1\n")
|
|
77
|
+
|
|
78
|
+
assert_equal({ 'host' => 'h', 'port' => 1 }, @klass.dds[:prod].to_hash)
|
|
79
|
+
end
|
|
80
|
+
|
|
81
|
+
def test_yaml_dates_and_times_load
|
|
82
|
+
write('dds.yaml', "day: 2026-12-01\nat: 2026-12-01 10:00:00 +00:00\n")
|
|
83
|
+
|
|
84
|
+
assert_equal(Date.new(2026, 12, 1), @klass.dds[:day])
|
|
85
|
+
assert_kind_of(Time, @klass.dds[:at])
|
|
86
|
+
end
|
|
87
|
+
end
|
|
@@ -0,0 +1,72 @@
|
|
|
1
|
+
# frozen_string_literal: true
|
|
2
|
+
|
|
3
|
+
$LOAD_PATH.push(File.join(File.dirname(__FILE__), '..', 'lib'))
|
|
4
|
+
require 'minitest/autorun'
|
|
5
|
+
require 'config_files'
|
|
6
|
+
require 'fileutils'
|
|
7
|
+
require 'tmpdir'
|
|
8
|
+
|
|
9
|
+
# Files next to a config file that share its name but are not config files
|
|
10
|
+
# (editor backups, saved copies) must not be loaded or merged.
|
|
11
|
+
class StrayFilesTest < Minitest::Test
|
|
12
|
+
def setup
|
|
13
|
+
@dir = Dir.mktmpdir('config_files_stray')
|
|
14
|
+
File.write(File.join(@dir, 'dds.yaml'), "current: yes\nshared: new\n")
|
|
15
|
+
@klass = Class.new do
|
|
16
|
+
include ConfigFiles
|
|
17
|
+
end
|
|
18
|
+
@klass.config_directories(etc: [@dir])
|
|
19
|
+
@klass.dynamic_config_files(:dds)
|
|
20
|
+
end
|
|
21
|
+
|
|
22
|
+
def teardown
|
|
23
|
+
FileUtils.rm_rf(@dir)
|
|
24
|
+
end
|
|
25
|
+
|
|
26
|
+
def write(name, content = "shared: old\nstale: true\n")
|
|
27
|
+
File.write(File.join(@dir, name), content)
|
|
28
|
+
end
|
|
29
|
+
|
|
30
|
+
def loaded_names
|
|
31
|
+
@klass.send(:all_config_files, :dds).map { |f| File.basename(f) }
|
|
32
|
+
end
|
|
33
|
+
|
|
34
|
+
def test_save_file_beside_yaml_is_ignored
|
|
35
|
+
write('dds.yaml.save')
|
|
36
|
+
|
|
37
|
+
assert_equal(['dds.yaml'], loaded_names)
|
|
38
|
+
assert_equal('new', @klass.dds[:shared])
|
|
39
|
+
assert_nil(@klass.dds[:stale])
|
|
40
|
+
end
|
|
41
|
+
|
|
42
|
+
def test_common_backup_suffixes_are_ignored
|
|
43
|
+
%w[dds.yaml.bak dds.yaml.orig dds.yaml~ dds.bak dds.txt].each { |name| write(name) }
|
|
44
|
+
|
|
45
|
+
assert_equal(['dds.yaml'], loaded_names)
|
|
46
|
+
assert_equal('new', @klass.dds[:shared])
|
|
47
|
+
end
|
|
48
|
+
|
|
49
|
+
def test_differently_named_file_with_registered_extension_is_ignored
|
|
50
|
+
write('dds.old.yaml')
|
|
51
|
+
|
|
52
|
+
assert_equal(['dds.yaml'], loaded_names)
|
|
53
|
+
assert_equal('new', @klass.dds[:shared])
|
|
54
|
+
end
|
|
55
|
+
|
|
56
|
+
def test_every_registered_extension_is_still_loaded
|
|
57
|
+
write('dds.yml', "yml: true\n")
|
|
58
|
+
write('dds.json', '{"json": true}')
|
|
59
|
+
write('dds.conf', "conf=true\n")
|
|
60
|
+
write('dds.ini', "ini=true\n")
|
|
61
|
+
write('dds.xml', '<config><xml>true</xml></config>')
|
|
62
|
+
|
|
63
|
+
assert_equal(%w[dds.conf dds.ini dds.json dds.xml dds.yaml dds.yml], loaded_names)
|
|
64
|
+
end
|
|
65
|
+
|
|
66
|
+
def test_extension_match_is_case_insensitive
|
|
67
|
+
FileUtils.rm(File.join(@dir, 'dds.yaml'))
|
|
68
|
+
write('dds.YAML', "upper: true\n")
|
|
69
|
+
|
|
70
|
+
assert_equal(['dds.YAML'], loaded_names)
|
|
71
|
+
end
|
|
72
|
+
end
|
metadata
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: config_files
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 0.2.
|
|
4
|
+
version: 0.2.2
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Paul McKibbin
|
|
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
|
|
@@ -16,9 +16,6 @@ dependencies:
|
|
|
16
16
|
- - ">="
|
|
17
17
|
- !ruby/object:Gem::Version
|
|
18
18
|
version: '6.1'
|
|
19
|
-
- - "<"
|
|
20
|
-
- !ruby/object:Gem::Version
|
|
21
|
-
version: '8.0'
|
|
22
19
|
type: :runtime
|
|
23
20
|
prerelease: false
|
|
24
21
|
version_requirements: !ruby/object:Gem::Requirement
|
|
@@ -26,9 +23,6 @@ dependencies:
|
|
|
26
23
|
- - ">="
|
|
27
24
|
- !ruby/object:Gem::Version
|
|
28
25
|
version: '6.1'
|
|
29
|
-
- - "<"
|
|
30
|
-
- !ruby/object:Gem::Version
|
|
31
|
-
version: '8.0'
|
|
32
26
|
- !ruby/object:Gem::Dependency
|
|
33
27
|
name: rexml
|
|
34
28
|
requirement: !ruby/object:Gem::Requirement
|
|
@@ -87,12 +81,14 @@ files:
|
|
|
87
81
|
- test/etc/dummy.json
|
|
88
82
|
- test/etc/dummy.xml
|
|
89
83
|
- test/etc/dummy.yml
|
|
84
|
+
- test/load_robustness_test.rb
|
|
90
85
|
- test/loader_factory_test.rb
|
|
91
86
|
- test/loaders_test.rb
|
|
92
87
|
- test/local/dummy.json
|
|
93
88
|
- test/local/dummy.yml
|
|
94
89
|
- test/mixed_format_test.rb
|
|
95
90
|
- test/multi_directory_test.rb
|
|
91
|
+
- test/stray_files_test.rb
|
|
96
92
|
- test/test_helper.rb
|
|
97
93
|
homepage: https://github.com/blackrat/config_files
|
|
98
94
|
licenses:
|
|
@@ -113,7 +109,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
|
113
109
|
- !ruby/object:Gem::Version
|
|
114
110
|
version: '0'
|
|
115
111
|
requirements: []
|
|
116
|
-
rubygems_version:
|
|
112
|
+
rubygems_version: 4.0.16
|
|
117
113
|
specification_version: 4
|
|
118
114
|
summary: ConfigFiles is a configuration file access tool. It parses multiple configuration
|
|
119
115
|
files in multiple formats and presents a consistent block to the application with
|