config_files 0.1.6 → 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.
Files changed (45) hide show
  1. checksums.yaml +4 -4
  2. data/.github/workflows/ci.yml +94 -0
  3. data/.gitignore +2 -3
  4. data/.rubocop.yml +81 -0
  5. data/CHANGELOG.md +154 -0
  6. data/Gemfile +12 -1
  7. data/MULTI_RUBY_SETUP.md +158 -0
  8. data/README.md +246 -23
  9. data/Rakefile +26 -3
  10. data/TESTING.md +226 -0
  11. data/config_files.gemspec +12 -9
  12. data/docker/Dockerfile.test +32 -0
  13. data/lib/config_files/file_factory.rb +7 -3
  14. data/lib/config_files/loader_factory.rb +20 -11
  15. data/lib/config_files/loaders/base_parser.rb +133 -0
  16. data/lib/config_files/loaders/conf.rb +61 -0
  17. data/lib/config_files/loaders/default.rb +3 -1
  18. data/lib/config_files/loaders/ini.rb +48 -0
  19. data/lib/config_files/loaders/json.rb +3 -1
  20. data/lib/config_files/loaders/xml.rb +67 -0
  21. data/lib/config_files/loaders/yaml.rb +2 -0
  22. data/lib/config_files/loaders.rb +6 -1
  23. data/lib/config_files/version.rb +3 -1
  24. data/lib/config_files.rb +34 -18
  25. data/lib/meta.rb +3 -1
  26. data/scripts/install_rubies_asdf.sh +187 -0
  27. data/scripts/test_docker.sh +91 -0
  28. data/scripts/test_multiple_rubies.sh +290 -0
  29. data/test/comprehensive_multi_directory_test.rb +168 -0
  30. data/test/config/dummy.json +10 -0
  31. data/test/config/dummy.yml +6 -0
  32. data/test/config_files_test.rb +10 -8
  33. data/test/etc/dummy.conf +14 -2
  34. data/test/etc/dummy.ini +12 -0
  35. data/test/etc/dummy.xml +13 -0
  36. data/test/etc/dummy.yml +2 -2
  37. data/test/loader_factory_test.rb +10 -10
  38. data/test/loaders_test.rb +362 -0
  39. data/test/local/dummy.json +10 -0
  40. data/test/local/dummy.yml +6 -0
  41. data/test/mixed_format_test.rb +152 -0
  42. data/test/multi_directory_test.rb +126 -0
  43. data/test/test_helper.rb +3 -0
  44. metadata +49 -26
  45. data/Gemfile.lock +0 -34
@@ -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
@@ -0,0 +1,3 @@
1
+ $LOAD_PATH.push(File.join(File.dirname(__FILE__), '..', 'lib'))
2
+ require 'minitest/autorun'
3
+ require 'config_files'
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.6
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: 2012-11-11 00:00:00.000000000 Z
10
+ date: 2025-09-27 00:00:00.000000000 Z
12
11
  dependencies:
13
12
  - !ruby/object:Gem::Dependency
14
13
  name: activesupport
@@ -16,62 +15,90 @@ dependencies:
16
15
  requirements:
17
16
  - - ">="
18
17
  - !ruby/object:Gem::Version
19
- version: 2.2.1
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: 2.2.1
28
+ version: '6.1'
29
+ - - "<"
30
+ - !ruby/object:Gem::Version
31
+ version: '8.0'
27
32
  - !ruby/object:Gem::Dependency
28
- name: rake
33
+ name: rexml
29
34
  requirement: !ruby/object:Gem::Requirement
30
35
  requirements:
31
- - - ">="
36
+ - - "~>"
32
37
  - !ruby/object:Gem::Version
33
- version: '0'
34
- type: :development
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: '0'
41
- description: A configuration tool for using multiple configuration files with multiple
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
- - Gemfile.lock
52
58
  - LICENCE.txt
59
+ - MULTI_RUBY_SETUP.md
53
60
  - README.md
54
61
  - Rakefile
62
+ - TESTING.md
55
63
  - config_files.gemspec
64
+ - docker/Dockerfile.test
56
65
  - lib/config_files.rb
57
66
  - lib/config_files/file_factory.rb
58
67
  - lib/config_files/loader_factory.rb
59
68
  - lib/config_files/loaders.rb
69
+ - lib/config_files/loaders/base_parser.rb
70
+ - lib/config_files/loaders/conf.rb
60
71
  - lib/config_files/loaders/default.rb
72
+ - lib/config_files/loaders/ini.rb
61
73
  - lib/config_files/loaders/json.rb
74
+ - lib/config_files/loaders/xml.rb
62
75
  - lib/config_files/loaders/yaml.rb
63
76
  - lib/config_files/version.rb
64
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
65
84
  - test/config_files_test.rb
66
85
  - test/etc/dummy.conf
86
+ - test/etc/dummy.ini
67
87
  - test/etc/dummy.json
88
+ - test/etc/dummy.xml
68
89
  - test/etc/dummy.yml
69
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
70
97
  homepage: https://github.com/blackrat/config_files
71
98
  licenses:
72
99
  - MIT
73
- metadata: {}
74
- post_install_message:
100
+ metadata:
101
+ rubygems_mfa_required: 'true'
75
102
  rdoc_options: []
76
103
  require_paths:
77
104
  - lib
@@ -79,22 +106,18 @@ required_ruby_version: !ruby/object:Gem::Requirement
79
106
  requirements:
80
107
  - - ">="
81
108
  - !ruby/object:Gem::Version
82
- version: '0'
109
+ version: 2.7.0
83
110
  required_rubygems_version: !ruby/object:Gem::Requirement
84
111
  requirements:
85
112
  - - ">="
86
113
  - !ruby/object:Gem::Version
87
114
  version: '0'
88
115
  requirements: []
89
- rubygems_version: 3.1.4
90
- signing_key:
116
+ rubygems_version: 3.6.2
91
117
  specification_version: 4
92
118
  summary: ConfigFiles is a configuration file access tool. It parses multiple configuration
93
119
  files in multiple formats and presents a consistent block to the application with
94
- options to cache or use the files dynamically
95
- test_files:
96
- - test/config_files_test.rb
97
- - test/etc/dummy.conf
98
- - test/etc/dummy.json
99
- - test/etc/dummy.yml
100
- - 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: []
data/Gemfile.lock DELETED
@@ -1,34 +0,0 @@
1
- PATH
2
- remote: .
3
- specs:
4
- config_files (0.1.5)
5
- activesupport (>= 2.2.1)
6
-
7
- GEM
8
- remote: https://rubygems.org/
9
- specs:
10
- activesupport (6.0.3.3)
11
- concurrent-ruby (~> 1.0, >= 1.0.2)
12
- i18n (>= 0.7, < 2)
13
- minitest (~> 5.1)
14
- tzinfo (~> 1.1)
15
- zeitwerk (~> 2.2, >= 2.2.2)
16
- concurrent-ruby (1.1.7)
17
- i18n (1.8.5)
18
- concurrent-ruby (~> 1.0)
19
- minitest (5.14.2)
20
- rake (13.0.1)
21
- thread_safe (0.3.6)
22
- tzinfo (1.2.7)
23
- thread_safe (~> 0.1)
24
- zeitwerk (2.4.0)
25
-
26
- PLATFORMS
27
- ruby
28
-
29
- DEPENDENCIES
30
- config_files!
31
- rake
32
-
33
- BUNDLED WITH
34
- 1.16.1