config_files 0.1.7 → 0.2.1
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 +94 -0
- data/.gitignore +2 -5
- data/.rubocop.yml +81 -0
- data/CHANGELOG.md +154 -0
- data/Gemfile +12 -1
- data/MULTI_RUBY_SETUP.md +158 -0
- data/README.md +246 -23
- data/Rakefile +26 -3
- data/TESTING.md +226 -0
- data/config_files.gemspec +12 -9
- data/docker/Dockerfile.test +32 -0
- data/lib/config_files/file_factory.rb +7 -3
- data/lib/config_files/loader_factory.rb +20 -11
- data/lib/config_files/loaders/base_parser.rb +133 -0
- data/lib/config_files/loaders/conf.rb +61 -0
- data/lib/config_files/loaders/default.rb +3 -1
- data/lib/config_files/loaders/ini.rb +48 -0
- data/lib/config_files/loaders/json.rb +3 -1
- data/lib/config_files/loaders/xml.rb +67 -0
- data/lib/config_files/loaders/yaml.rb +2 -0
- data/lib/config_files/loaders.rb +6 -1
- data/lib/config_files/version.rb +3 -1
- data/lib/config_files.rb +33 -18
- data/lib/meta.rb +3 -1
- data/scripts/install_rubies_asdf.sh +187 -0
- data/scripts/test_docker.sh +91 -0
- data/scripts/test_multiple_rubies.sh +290 -0
- data/test/comprehensive_multi_directory_test.rb +168 -0
- data/test/config/dummy.json +10 -0
- data/test/config/dummy.yml +6 -0
- data/test/config_files_test.rb +8 -6
- data/test/etc/dummy.conf +14 -2
- data/test/etc/dummy.ini +12 -0
- data/test/etc/dummy.xml +13 -0
- data/test/loader_factory_test.rb +10 -10
- data/test/loaders_test.rb +362 -0
- data/test/local/dummy.json +10 -0
- data/test/local/dummy.yml +6 -0
- data/test/mixed_format_test.rb +152 -0
- data/test/multi_directory_test.rb +126 -0
- data/test/test_helper.rb +3 -0
- metadata +49 -25
@@ -0,0 +1,126 @@
|
|
1
|
+
$LOAD_PATH.push(File.join(File.dirname(__FILE__), '..', 'lib'))
|
2
|
+
require 'minitest/autorun'
|
3
|
+
require 'config_files'
|
4
|
+
|
5
|
+
class MultiDirectoryDummy
|
6
|
+
include ConfigFiles
|
7
|
+
config_directories etc: ['test/config', 'test/etc', 'test/local']
|
8
|
+
static_config_files :dummy
|
9
|
+
end
|
10
|
+
|
11
|
+
class MultiDirectoryDynamic
|
12
|
+
include ConfigFiles
|
13
|
+
config_directories etc: ['test/config', 'test/etc', 'test/local']
|
14
|
+
dynamic_config_files :dummy
|
15
|
+
end
|
16
|
+
|
17
|
+
class SingleDirectoryForComparison
|
18
|
+
include ConfigFiles
|
19
|
+
config_directories etc: ['test/etc']
|
20
|
+
static_config_files :dummy
|
21
|
+
end
|
22
|
+
|
23
|
+
class MissingDirTest
|
24
|
+
include ConfigFiles
|
25
|
+
config_directories etc: ['test/nonexistent', 'test/etc']
|
26
|
+
static_config_files :dummy
|
27
|
+
end
|
28
|
+
|
29
|
+
class NoFilesTest
|
30
|
+
include ConfigFiles
|
31
|
+
config_directories etc: ['test/config', 'test/etc', 'test/local']
|
32
|
+
static_config_files :nonexistent
|
33
|
+
end
|
34
|
+
|
35
|
+
class MultiDirectoryTest < Minitest::Test
|
36
|
+
def test_loads_from_all_directories
|
37
|
+
config = MultiDirectoryDummy.dummy
|
38
|
+
|
39
|
+
# Should have values from all directories
|
40
|
+
assert config.key?(:config_test), "Should have config_test key"
|
41
|
+
assert config.key?(:only_in_config), "Should have only_in_config from config dir"
|
42
|
+
assert config.key?(:only_in_yaml), "Should have only_in_yaml from etc dir"
|
43
|
+
assert config.key?(:only_in_local), "Should have only_in_local from local dir"
|
44
|
+
end
|
45
|
+
|
46
|
+
def test_earlier_directories_override_later_ones
|
47
|
+
config = MultiDirectoryDummy.dummy
|
48
|
+
|
49
|
+
# config_test should be from config directory (first in list)
|
50
|
+
assert_equal 'config_dir_value', config[:config_test]
|
51
|
+
|
52
|
+
# shared_key should also be from config directory (first in list)
|
53
|
+
assert_equal 'from_config', config[:shared_key]
|
54
|
+
end
|
55
|
+
|
56
|
+
def test_deep_merge_behavior_for_nested_hashes
|
57
|
+
config = MultiDirectoryDummy.dummy
|
58
|
+
|
59
|
+
# Database config should be deep merged with config dir taking precedence
|
60
|
+
assert config[:database], "Should have database config"
|
61
|
+
assert_equal 'config.example.com', config[:database][:host], "Host should be from config dir (highest priority)"
|
62
|
+
assert_equal 5432, config[:database][:port], "Port should come from config dir"
|
63
|
+
assert_equal 'local_user', config[:database][:username], "Username should come from local dir (only place it exists)"
|
64
|
+
end
|
65
|
+
|
66
|
+
def test_json_files_are_also_merged_across_directories
|
67
|
+
config = MultiDirectoryDummy.dummy
|
68
|
+
|
69
|
+
# API config should be deep merged from JSON files with config dir taking precedence
|
70
|
+
assert config[:api], "Should have API config from JSON files"
|
71
|
+
assert_equal 'https://api.config.com', config[:api][:endpoint], "Endpoint should be from config dir (highest priority)"
|
72
|
+
assert_equal 30, config[:api][:timeout], "Timeout should come from config dir"
|
73
|
+
assert config[:api][:debug], "Debug should come from local dir (only place it exists)"
|
74
|
+
end
|
75
|
+
|
76
|
+
def test_array_values_in_nested_structures_are_merged
|
77
|
+
config = MultiDirectoryDummy.dummy
|
78
|
+
|
79
|
+
# Features should be merged with config dir taking precedence
|
80
|
+
assert config[:features], "Should have features config"
|
81
|
+
assert config[:features][:feature_a], "feature_a should come from config dir"
|
82
|
+
refute config[:features][:feature_b], "feature_b should be from config dir (highest priority)"
|
83
|
+
assert config[:features][:feature_c], "feature_c should come from local dir (only place it exists)"
|
84
|
+
end
|
85
|
+
|
86
|
+
def test_dynamic_config_files_also_work_with_multiple_directories
|
87
|
+
config = MultiDirectoryDynamic.dummy
|
88
|
+
|
89
|
+
# Should behave the same as static config files
|
90
|
+
assert_equal 'config_dir_value', config[:config_test]
|
91
|
+
assert config.key?(:only_in_config)
|
92
|
+
assert config.key?(:only_in_yaml)
|
93
|
+
assert config.key?(:only_in_local)
|
94
|
+
end
|
95
|
+
|
96
|
+
def test_single_directory_behavior_unchanged
|
97
|
+
config = SingleDirectoryForComparison.dummy
|
98
|
+
|
99
|
+
# Should only have values from etc directory
|
100
|
+
assert_equal 'test', config[:config_test]
|
101
|
+
assert config.key?(:only_in_yaml)
|
102
|
+
refute config.key?(:only_in_config), "Should not have config dir values"
|
103
|
+
refute config.key?(:only_in_local), "Should not have local dir values"
|
104
|
+
end
|
105
|
+
|
106
|
+
def test_missing_directories_are_handled_gracefully
|
107
|
+
config = MissingDirTest.dummy
|
108
|
+
# Should still work with existing directories
|
109
|
+
assert_equal 'test', config[:config_test]
|
110
|
+
end
|
111
|
+
|
112
|
+
def test_empty_result_when_no_files_found
|
113
|
+
config = NoFilesTest.nonexistent
|
114
|
+
|
115
|
+
assert_empty(config)
|
116
|
+
end
|
117
|
+
|
118
|
+
def test_file_extensions_are_processed_correctly_across_directories
|
119
|
+
config = MultiDirectoryDummy.dummy
|
120
|
+
|
121
|
+
# Should have values from .yml, .json, and .conf files across all directories
|
122
|
+
assert config.key?(:only_in_yaml), "Should process .yml files"
|
123
|
+
assert config.key?(:testId), "Should process .json files"
|
124
|
+
assert config.key?(:only_in_conf), "Should process .conf files"
|
125
|
+
end
|
126
|
+
end
|
data/test/test_helper.rb
ADDED
metadata
CHANGED
@@ -1,14 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: config_files
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.1
|
4
|
+
version: 0.2.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Paul McKibbin
|
8
|
-
autorequire:
|
9
8
|
bindir: bin
|
10
9
|
cert_chain: []
|
11
|
-
date:
|
10
|
+
date: 2025-09-27 00:00:00.000000000 Z
|
12
11
|
dependencies:
|
13
12
|
- !ruby/object:Gem::Dependency
|
14
13
|
name: activesupport
|
@@ -16,61 +15,90 @@ dependencies:
|
|
16
15
|
requirements:
|
17
16
|
- - ">="
|
18
17
|
- !ruby/object:Gem::Version
|
19
|
-
version:
|
18
|
+
version: '6.1'
|
19
|
+
- - "<"
|
20
|
+
- !ruby/object:Gem::Version
|
21
|
+
version: '8.0'
|
20
22
|
type: :runtime
|
21
23
|
prerelease: false
|
22
24
|
version_requirements: !ruby/object:Gem::Requirement
|
23
25
|
requirements:
|
24
26
|
- - ">="
|
25
27
|
- !ruby/object:Gem::Version
|
26
|
-
version:
|
28
|
+
version: '6.1'
|
29
|
+
- - "<"
|
30
|
+
- !ruby/object:Gem::Version
|
31
|
+
version: '8.0'
|
27
32
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
33
|
+
name: rexml
|
29
34
|
requirement: !ruby/object:Gem::Requirement
|
30
35
|
requirements:
|
31
|
-
- - "
|
36
|
+
- - "~>"
|
32
37
|
- !ruby/object:Gem::Version
|
33
|
-
version: '
|
34
|
-
type: :
|
38
|
+
version: '3.2'
|
39
|
+
type: :runtime
|
35
40
|
prerelease: false
|
36
41
|
version_requirements: !ruby/object:Gem::Requirement
|
37
42
|
requirements:
|
38
|
-
- - "
|
43
|
+
- - "~>"
|
39
44
|
- !ruby/object:Gem::Version
|
40
|
-
version: '
|
41
|
-
description:
|
42
|
-
formats by presenting them as a hash.
|
45
|
+
version: '3.2'
|
46
|
+
description: Configuration tool for cascading configuration files with multiple formats
|
43
47
|
email:
|
44
48
|
- pmckibbin@gmail.com
|
45
49
|
executables: []
|
46
50
|
extensions: []
|
47
51
|
extra_rdoc_files: []
|
48
52
|
files:
|
53
|
+
- ".github/workflows/ci.yml"
|
49
54
|
- ".gitignore"
|
55
|
+
- ".rubocop.yml"
|
56
|
+
- CHANGELOG.md
|
50
57
|
- Gemfile
|
51
58
|
- LICENCE.txt
|
59
|
+
- MULTI_RUBY_SETUP.md
|
52
60
|
- README.md
|
53
61
|
- Rakefile
|
62
|
+
- TESTING.md
|
54
63
|
- config_files.gemspec
|
64
|
+
- docker/Dockerfile.test
|
55
65
|
- lib/config_files.rb
|
56
66
|
- lib/config_files/file_factory.rb
|
57
67
|
- lib/config_files/loader_factory.rb
|
58
68
|
- lib/config_files/loaders.rb
|
69
|
+
- lib/config_files/loaders/base_parser.rb
|
70
|
+
- lib/config_files/loaders/conf.rb
|
59
71
|
- lib/config_files/loaders/default.rb
|
72
|
+
- lib/config_files/loaders/ini.rb
|
60
73
|
- lib/config_files/loaders/json.rb
|
74
|
+
- lib/config_files/loaders/xml.rb
|
61
75
|
- lib/config_files/loaders/yaml.rb
|
62
76
|
- lib/config_files/version.rb
|
63
77
|
- lib/meta.rb
|
78
|
+
- scripts/install_rubies_asdf.sh
|
79
|
+
- scripts/test_docker.sh
|
80
|
+
- scripts/test_multiple_rubies.sh
|
81
|
+
- test/comprehensive_multi_directory_test.rb
|
82
|
+
- test/config/dummy.json
|
83
|
+
- test/config/dummy.yml
|
64
84
|
- test/config_files_test.rb
|
65
85
|
- test/etc/dummy.conf
|
86
|
+
- test/etc/dummy.ini
|
66
87
|
- test/etc/dummy.json
|
88
|
+
- test/etc/dummy.xml
|
67
89
|
- test/etc/dummy.yml
|
68
90
|
- test/loader_factory_test.rb
|
91
|
+
- test/loaders_test.rb
|
92
|
+
- test/local/dummy.json
|
93
|
+
- test/local/dummy.yml
|
94
|
+
- test/mixed_format_test.rb
|
95
|
+
- test/multi_directory_test.rb
|
96
|
+
- test/test_helper.rb
|
69
97
|
homepage: https://github.com/blackrat/config_files
|
70
98
|
licenses:
|
71
99
|
- MIT
|
72
|
-
metadata:
|
73
|
-
|
100
|
+
metadata:
|
101
|
+
rubygems_mfa_required: 'true'
|
74
102
|
rdoc_options: []
|
75
103
|
require_paths:
|
76
104
|
- lib
|
@@ -78,22 +106,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
78
106
|
requirements:
|
79
107
|
- - ">="
|
80
108
|
- !ruby/object:Gem::Version
|
81
|
-
version:
|
109
|
+
version: 2.7.0
|
82
110
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
83
111
|
requirements:
|
84
112
|
- - ">="
|
85
113
|
- !ruby/object:Gem::Version
|
86
114
|
version: '0'
|
87
115
|
requirements: []
|
88
|
-
rubygems_version: 3.
|
89
|
-
signing_key:
|
116
|
+
rubygems_version: 3.6.2
|
90
117
|
specification_version: 4
|
91
118
|
summary: ConfigFiles is a configuration file access tool. It parses multiple configuration
|
92
119
|
files in multiple formats and presents a consistent block to the application with
|
93
|
-
options to cache or use the files dynamically
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
- test/etc/dummy.json
|
98
|
-
- test/etc/dummy.yml
|
99
|
-
- test/loader_factory_test.rb
|
120
|
+
options to cache or use the files dynamically. It uses a priority directory ordering
|
121
|
+
to find the files, and an alphabetical ordering to give precedence to the files
|
122
|
+
in that directory.
|
123
|
+
test_files: []
|