unified_settings 0.1.1 → 0.2.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 101e91d0a5df136386e9f59565bfd7ca7f170df66f192673926728e43c5d4db6
4
- data.tar.gz: fa08264388a6c5b13b90bbae7cbe760bc3fe9c33594e65133cfac604b4c5755c
3
+ metadata.gz: 73896f0aecb4e9798a501cb5e3e87c68ae50b0f0531ea50491d830859897c42f
4
+ data.tar.gz: 0bca6f0c037cf42bb8b9961474ed5145fe4e436ffe3598f30e16aa756ae0909e
5
5
  SHA512:
6
- metadata.gz: 7c2e086a138bf4d72b96e736ba2a8a1cdad17902879aca658d19e365c4e77e3aa126f57dbc769897a0c51c17c708c3d31322088d5bf0c6d4e946617168bb23e5
7
- data.tar.gz: 6677d274137f86bb1542e26442d3ab69a283767c814876a22286be605430fcdaf4b3096b249488694036bf8a4056945c1dc9d5c10515ca72d309ef9ee18cd3da
6
+ metadata.gz: 7335dc6d9447df99efa67c754e5b36e1f3d9e49a3f62506a611e7406252db2313c9dac8b48b69fdc0680e15a5b40a5afe74046de32f3a36d59f4645861d6a0c9
7
+ data.tar.gz: 0e3e1a4b839e5483c8a16ed0f7cbfb76d267b828ed7ea8061cf05c847613c433ebe4d506d64e392510d3c4f45207b30282cabecc62dc19b564ce724e766ce4fe
data/.rubocop.yml CHANGED
@@ -15,6 +15,7 @@ AllCops:
15
15
  - 'config/**/*'
16
16
  - 'vendor/**/*'
17
17
  - 'bin/**/*'
18
+ - 'test/dummy/**/*'
18
19
 
19
20
  Layout/LineLength:
20
21
  Max: 80
@@ -48,6 +49,10 @@ Metrics/ModuleLength:
48
49
  Minitest/MultipleAssertions:
49
50
  Max: 10
50
51
 
52
+ Rails/RakeEnvironment:
53
+ Exclude:
54
+ - 'Rakefile'
55
+
51
56
  Rails/RefuteMethods:
52
57
  Exclude:
53
58
  - 'test/**/*'
data/.ruby-version CHANGED
@@ -1 +1 @@
1
- ruby-3.2.2
1
+ ruby-3.3.6
data/Gemfile CHANGED
@@ -7,7 +7,6 @@ gemspec
7
7
 
8
8
  gem 'bundler', '~> 2.3'
9
9
  gem 'bundler-audit', '>= 0'
10
- gem 'config', '>= 3.0'
11
10
  gem 'minitest', '~> 5.0'
12
11
  gem 'rake', '~> 13.0'
13
12
  gem 'rubocop', '~> 1.21'
@@ -16,3 +15,78 @@ gem 'rubocop-performance', '>= 0'
16
15
  gem 'rubocop-rails', '>= 0'
17
16
  gem 'rubocop-rake', '>= 0'
18
17
  gem 'ruby_audit', '>= 0'
18
+
19
+ ##
20
+ ## Rails App Gemfile contents
21
+ ##
22
+
23
+ # Bundle edge Rails instead: gem "rails", github: "rails/rails", branch: "main"
24
+ gem 'rails', '~> 8.0.0'
25
+
26
+ # The modern asset pipeline for Rails
27
+ # https://github.com/rails/propshaft
28
+ gem 'propshaft'
29
+
30
+ # Use the Puma web server
31
+ # [https://github.com/puma/puma]
32
+ gem 'puma', '~> 6.0'
33
+
34
+ # Build JSON APIs with ease
35
+ # [https://github.com/rails/jbuilder]
36
+ # gem 'jbuilder'
37
+
38
+ # Use Kredis to get higher-level data types in Redis
39
+ # [https://github.com/rails/kredis]
40
+ # gem "kredis"
41
+
42
+ # Use Active Model has_secure_password
43
+ # [https://guides.rubyonrails.org/active_model_basics.html#securepassword]
44
+ # gem "bcrypt", "~> 3.1.7"
45
+
46
+ # Windows does not include zoneinfo files, so bundle the tzinfo-data gem
47
+ gem 'tzinfo-data', platforms: %i[mingw mswin x64_mingw jruby]
48
+
49
+ # Reduces boot times through caching; required in config/boot.rb
50
+ gem 'bootsnap', require: false
51
+
52
+ # Bundle and process CSS
53
+ # https://github.com/rails/cssbundling-rails
54
+ gem 'cssbundling-rails'
55
+
56
+ # Use Sass to process CSS
57
+ # gem "sassc-rails"
58
+
59
+ group :development, :test do
60
+ # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
61
+ gem 'debug', platforms: %i[mri mingw x64_mingw]
62
+ end
63
+
64
+ group :development do
65
+ # Use console on exceptions pages [https://github.com/rails/web-console]
66
+ # gem 'web-console'
67
+
68
+ # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
69
+ # gem "rack-mini-profiler"
70
+
71
+ # Speed up commands on slow machines / big apps
72
+ # [https://github.com/rails/spring]
73
+ # gem "spring"
74
+ end
75
+
76
+ group :test do
77
+ # Use system testing
78
+ # [https://guides.rubyonrails.org/testing.html#system-testing]
79
+ gem 'capybara'
80
+ gem 'selenium-webdriver'
81
+ gem 'webdrivers'
82
+ end
83
+
84
+ #
85
+ # Gem that has been added to default Gemfile so that we can run the tests
86
+ # for the handlers
87
+ #
88
+
89
+ #
90
+ # Add multi-environment yaml settings to rails
91
+ # https://github.com/rubyconfig/config
92
+ gem 'config', '>= 3.0'
data/Gemfile.lock CHANGED
@@ -1,123 +1,293 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- unified_settings (0.1.1)
4
+ unified_settings (0.2.0)
5
5
  activerecord (> 4.2.0)
6
6
  activesupport (> 4.2.0)
7
7
 
8
8
  GEM
9
9
  remote: https://rubygems.org/
10
10
  specs:
11
- activemodel (7.0.7)
12
- activesupport (= 7.0.7)
13
- activerecord (7.0.7)
14
- activemodel (= 7.0.7)
15
- activesupport (= 7.0.7)
16
- activesupport (7.0.7)
17
- concurrent-ruby (~> 1.0, >= 1.0.2)
11
+ actioncable (8.0.0)
12
+ actionpack (= 8.0.0)
13
+ activesupport (= 8.0.0)
14
+ nio4r (~> 2.0)
15
+ websocket-driver (>= 0.6.1)
16
+ zeitwerk (~> 2.6)
17
+ actionmailbox (8.0.0)
18
+ actionpack (= 8.0.0)
19
+ activejob (= 8.0.0)
20
+ activerecord (= 8.0.0)
21
+ activestorage (= 8.0.0)
22
+ activesupport (= 8.0.0)
23
+ mail (>= 2.8.0)
24
+ actionmailer (8.0.0)
25
+ actionpack (= 8.0.0)
26
+ actionview (= 8.0.0)
27
+ activejob (= 8.0.0)
28
+ activesupport (= 8.0.0)
29
+ mail (>= 2.8.0)
30
+ rails-dom-testing (~> 2.2)
31
+ actionpack (8.0.0)
32
+ actionview (= 8.0.0)
33
+ activesupport (= 8.0.0)
34
+ nokogiri (>= 1.8.5)
35
+ rack (>= 2.2.4)
36
+ rack-session (>= 1.0.1)
37
+ rack-test (>= 0.6.3)
38
+ rails-dom-testing (~> 2.2)
39
+ rails-html-sanitizer (~> 1.6)
40
+ useragent (~> 0.16)
41
+ actiontext (8.0.0)
42
+ actionpack (= 8.0.0)
43
+ activerecord (= 8.0.0)
44
+ activestorage (= 8.0.0)
45
+ activesupport (= 8.0.0)
46
+ globalid (>= 0.6.0)
47
+ nokogiri (>= 1.8.5)
48
+ actionview (8.0.0)
49
+ activesupport (= 8.0.0)
50
+ builder (~> 3.1)
51
+ erubi (~> 1.11)
52
+ rails-dom-testing (~> 2.2)
53
+ rails-html-sanitizer (~> 1.6)
54
+ activejob (8.0.0)
55
+ activesupport (= 8.0.0)
56
+ globalid (>= 0.3.6)
57
+ activemodel (8.0.0)
58
+ activesupport (= 8.0.0)
59
+ activerecord (8.0.0)
60
+ activemodel (= 8.0.0)
61
+ activesupport (= 8.0.0)
62
+ timeout (>= 0.4.0)
63
+ activestorage (8.0.0)
64
+ actionpack (= 8.0.0)
65
+ activejob (= 8.0.0)
66
+ activerecord (= 8.0.0)
67
+ activesupport (= 8.0.0)
68
+ marcel (~> 1.0)
69
+ activesupport (8.0.0)
70
+ base64
71
+ benchmark (>= 0.3)
72
+ bigdecimal
73
+ concurrent-ruby (~> 1.0, >= 1.3.1)
74
+ connection_pool (>= 2.2.5)
75
+ drb
18
76
  i18n (>= 1.6, < 2)
77
+ logger (>= 1.4.2)
19
78
  minitest (>= 5.1)
20
- tzinfo (~> 2.0)
79
+ securerandom (>= 0.3)
80
+ tzinfo (~> 2.0, >= 2.0.5)
81
+ uri (>= 0.13.1)
82
+ addressable (2.8.7)
83
+ public_suffix (>= 2.0.2, < 7.0)
21
84
  ast (2.4.2)
22
- base64 (0.1.1)
23
- bundler-audit (0.9.1)
85
+ base64 (0.2.0)
86
+ benchmark (0.4.0)
87
+ bigdecimal (3.1.8)
88
+ bootsnap (1.18.4)
89
+ msgpack (~> 1.2)
90
+ builder (3.3.0)
91
+ bundler-audit (0.9.2)
24
92
  bundler (>= 1.2.0, < 3)
25
93
  thor (~> 1.0)
26
- concurrent-ruby (1.2.2)
27
- config (4.2.1)
94
+ capybara (3.40.0)
95
+ addressable
96
+ matrix
97
+ mini_mime (>= 0.1.3)
98
+ nokogiri (~> 1.11)
99
+ rack (>= 1.6.0)
100
+ rack-test (>= 0.6.3)
101
+ regexp_parser (>= 1.5, < 3.0)
102
+ xpath (~> 3.2)
103
+ concurrent-ruby (1.3.4)
104
+ config (5.5.2)
28
105
  deep_merge (~> 1.2, >= 1.2.1)
29
- dry-validation (~> 1.0, >= 1.0.0)
106
+ ostruct
107
+ connection_pool (2.4.1)
108
+ crass (1.0.6)
109
+ cssbundling-rails (1.4.1)
110
+ railties (>= 6.0.0)
111
+ date (3.4.1)
112
+ debug (1.9.2)
113
+ irb (~> 1.10)
114
+ reline (>= 0.3.8)
30
115
  deep_merge (1.2.2)
31
- dry-configurable (1.1.0)
32
- dry-core (~> 1.0, < 2)
33
- zeitwerk (~> 2.6)
34
- dry-core (1.0.1)
35
- concurrent-ruby (~> 1.0)
36
- zeitwerk (~> 2.6)
37
- dry-inflector (1.0.0)
38
- dry-initializer (3.1.1)
39
- dry-logic (1.5.0)
116
+ drb (2.2.1)
117
+ erubi (1.13.0)
118
+ globalid (1.2.1)
119
+ activesupport (>= 6.1)
120
+ i18n (1.14.6)
40
121
  concurrent-ruby (~> 1.0)
41
- dry-core (~> 1.0, < 2)
42
- zeitwerk (~> 2.6)
43
- dry-schema (1.13.2)
44
- concurrent-ruby (~> 1.0)
45
- dry-configurable (~> 1.0, >= 1.0.1)
46
- dry-core (~> 1.0, < 2)
47
- dry-initializer (~> 3.0)
48
- dry-logic (>= 1.4, < 2)
49
- dry-types (>= 1.7, < 2)
50
- zeitwerk (~> 2.6)
51
- dry-types (1.7.1)
52
- concurrent-ruby (~> 1.0)
53
- dry-core (~> 1.0)
54
- dry-inflector (~> 1.0)
55
- dry-logic (~> 1.4)
56
- zeitwerk (~> 2.6)
57
- dry-validation (1.10.0)
58
- concurrent-ruby (~> 1.0)
59
- dry-core (~> 1.0, < 2)
60
- dry-initializer (~> 3.0)
61
- dry-schema (>= 1.12, < 2)
62
- zeitwerk (~> 2.6)
63
- i18n (1.14.1)
64
- concurrent-ruby (~> 1.0)
65
- json (2.6.3)
122
+ io-console (0.8.0)
123
+ irb (1.14.1)
124
+ rdoc (>= 4.0.0)
125
+ reline (>= 0.4.2)
126
+ json (2.9.0)
66
127
  language_server-protocol (3.17.0.3)
67
- minitest (5.19.0)
68
- parallel (1.23.0)
69
- parser (3.2.2.3)
128
+ logger (1.6.2)
129
+ loofah (2.23.1)
130
+ crass (~> 1.0.2)
131
+ nokogiri (>= 1.12.0)
132
+ mail (2.8.1)
133
+ mini_mime (>= 0.1.1)
134
+ net-imap
135
+ net-pop
136
+ net-smtp
137
+ marcel (1.0.4)
138
+ matrix (0.4.2)
139
+ mini_mime (1.1.5)
140
+ minitest (5.25.4)
141
+ msgpack (1.7.5)
142
+ net-imap (0.5.1)
143
+ date
144
+ net-protocol
145
+ net-pop (0.1.2)
146
+ net-protocol
147
+ net-protocol (0.2.2)
148
+ timeout
149
+ net-smtp (0.5.0)
150
+ net-protocol
151
+ nio4r (2.7.4)
152
+ nokogiri (1.16.8-x86_64-darwin)
153
+ racc (~> 1.4)
154
+ nokogiri (1.16.8-x86_64-linux)
155
+ racc (~> 1.4)
156
+ ostruct (0.6.1)
157
+ parallel (1.26.3)
158
+ parser (3.3.6.0)
70
159
  ast (~> 2.4.1)
71
160
  racc
72
- racc (1.7.1)
73
- rack (3.0.8)
161
+ propshaft (1.1.0)
162
+ actionpack (>= 7.0.0)
163
+ activesupport (>= 7.0.0)
164
+ rack
165
+ railties (>= 7.0.0)
166
+ psych (5.2.1)
167
+ date
168
+ stringio
169
+ public_suffix (6.0.1)
170
+ puma (6.5.0)
171
+ nio4r (~> 2.0)
172
+ racc (1.8.1)
173
+ rack (3.1.8)
174
+ rack-session (2.0.0)
175
+ rack (>= 3.0.0)
176
+ rack-test (2.1.0)
177
+ rack (>= 1.3)
178
+ rackup (2.2.1)
179
+ rack (>= 3)
180
+ rails (8.0.0)
181
+ actioncable (= 8.0.0)
182
+ actionmailbox (= 8.0.0)
183
+ actionmailer (= 8.0.0)
184
+ actionpack (= 8.0.0)
185
+ actiontext (= 8.0.0)
186
+ actionview (= 8.0.0)
187
+ activejob (= 8.0.0)
188
+ activemodel (= 8.0.0)
189
+ activerecord (= 8.0.0)
190
+ activestorage (= 8.0.0)
191
+ activesupport (= 8.0.0)
192
+ bundler (>= 1.15.0)
193
+ railties (= 8.0.0)
194
+ rails-dom-testing (2.2.0)
195
+ activesupport (>= 5.0.0)
196
+ minitest
197
+ nokogiri (>= 1.6)
198
+ rails-html-sanitizer (1.6.1)
199
+ loofah (~> 2.21)
200
+ nokogiri (>= 1.15.7, != 1.16.7, != 1.16.6, != 1.16.5, != 1.16.4, != 1.16.3, != 1.16.2, != 1.16.1, != 1.16.0.rc1, != 1.16.0)
201
+ railties (8.0.0)
202
+ actionpack (= 8.0.0)
203
+ activesupport (= 8.0.0)
204
+ irb (~> 1.13)
205
+ rackup (>= 1.0.0)
206
+ rake (>= 12.2)
207
+ thor (~> 1.0, >= 1.2.2)
208
+ zeitwerk (~> 2.6)
74
209
  rainbow (3.1.1)
75
- rake (13.0.6)
76
- regexp_parser (2.8.1)
77
- rexml (3.2.6)
78
- rubocop (1.56.0)
79
- base64 (~> 0.1.1)
210
+ rake (13.2.1)
211
+ rdoc (6.8.1)
212
+ psych (>= 4.0.0)
213
+ regexp_parser (2.9.3)
214
+ reline (0.5.12)
215
+ io-console (~> 0.5)
216
+ rexml (3.3.9)
217
+ rubocop (1.69.1)
80
218
  json (~> 2.3)
81
219
  language_server-protocol (>= 3.17.0)
82
220
  parallel (~> 1.10)
83
- parser (>= 3.2.2.3)
221
+ parser (>= 3.3.0.2)
84
222
  rainbow (>= 2.2.2, < 4.0)
85
- regexp_parser (>= 1.8, < 3.0)
86
- rexml (>= 3.2.5, < 4.0)
87
- rubocop-ast (>= 1.28.1, < 2.0)
223
+ regexp_parser (>= 2.9.3, < 3.0)
224
+ rubocop-ast (>= 1.36.2, < 2.0)
88
225
  ruby-progressbar (~> 1.7)
89
- unicode-display_width (>= 2.4.0, < 3.0)
90
- rubocop-ast (1.29.0)
91
- parser (>= 3.2.1.0)
92
- rubocop-minitest (0.31.0)
93
- rubocop (>= 1.39, < 2.0)
94
- rubocop-performance (1.19.0)
95
- rubocop (>= 1.7.0, < 2.0)
96
- rubocop-ast (>= 0.4.0)
97
- rubocop-rails (2.20.2)
226
+ unicode-display_width (>= 2.4.0, < 4.0)
227
+ rubocop-ast (1.36.2)
228
+ parser (>= 3.3.1.0)
229
+ rubocop-minitest (0.36.0)
230
+ rubocop (>= 1.61, < 2.0)
231
+ rubocop-ast (>= 1.31.1, < 2.0)
232
+ rubocop-performance (1.23.0)
233
+ rubocop (>= 1.48.1, < 2.0)
234
+ rubocop-ast (>= 1.31.1, < 2.0)
235
+ rubocop-rails (2.27.0)
98
236
  activesupport (>= 4.2.0)
99
237
  rack (>= 1.1)
100
- rubocop (>= 1.33.0, < 2.0)
238
+ rubocop (>= 1.52.0, < 2.0)
239
+ rubocop-ast (>= 1.31.1, < 2.0)
101
240
  rubocop-rake (0.6.0)
102
241
  rubocop (~> 1.0)
103
242
  ruby-progressbar (1.13.0)
104
- ruby_audit (2.2.0)
243
+ ruby_audit (2.3.1)
105
244
  bundler-audit (~> 0.9.0)
106
- thor (1.2.2)
245
+ rubyzip (2.3.2)
246
+ securerandom (0.4.0)
247
+ selenium-webdriver (4.10.0)
248
+ rexml (~> 3.2, >= 3.2.5)
249
+ rubyzip (>= 1.2.2, < 3.0)
250
+ websocket (~> 1.0)
251
+ stringio (3.1.2)
252
+ thor (1.3.2)
253
+ timeout (0.4.2)
107
254
  tzinfo (2.0.6)
108
255
  concurrent-ruby (~> 1.0)
109
- unicode-display_width (2.4.2)
110
- zeitwerk (2.6.11)
256
+ unicode-display_width (3.1.2)
257
+ unicode-emoji (~> 4.0, >= 4.0.4)
258
+ unicode-emoji (4.0.4)
259
+ uri (1.0.2)
260
+ useragent (0.16.11)
261
+ webdrivers (5.3.1)
262
+ nokogiri (~> 1.6)
263
+ rubyzip (>= 1.3.0)
264
+ selenium-webdriver (~> 4.0, < 4.11)
265
+ websocket (1.2.11)
266
+ websocket-driver (0.7.6)
267
+ websocket-extensions (>= 0.1.0)
268
+ websocket-extensions (0.1.5)
269
+ xpath (3.2.0)
270
+ nokogiri (~> 1.8)
271
+ zeitwerk (2.7.1)
111
272
 
112
273
  PLATFORMS
113
274
  x86_64-darwin-22
275
+ x86_64-darwin-23
276
+ x86_64-darwin-24
114
277
  x86_64-linux
115
278
 
116
279
  DEPENDENCIES
280
+ bootsnap
117
281
  bundler (~> 2.3)
118
282
  bundler-audit
283
+ capybara
119
284
  config (>= 3.0)
285
+ cssbundling-rails
286
+ debug
120
287
  minitest (~> 5.0)
288
+ propshaft
289
+ puma (~> 6.0)
290
+ rails (~> 8.0.0)
121
291
  rake (~> 13.0)
122
292
  rubocop (~> 1.21)
123
293
  rubocop-minitest
@@ -125,7 +295,10 @@ DEPENDENCIES
125
295
  rubocop-rails
126
296
  rubocop-rake
127
297
  ruby_audit
298
+ selenium-webdriver
299
+ tzinfo-data
128
300
  unified_settings!
301
+ webdrivers
129
302
 
130
303
  BUNDLED WITH
131
- 2.4.10
304
+ 2.5.23
data/README.md CHANGED
@@ -7,7 +7,7 @@ A simple and unified way to get any setting in your code regardless of where it
7
7
 
8
8
  ## Installation
9
9
 
10
- Install the gem and add to the application's Gemfile by executing:
10
+ Install the gem and add it to the application's Gemfile by executing:
11
11
 
12
12
  $ bundle add unified_settings
13
13
 
@@ -27,14 +27,14 @@ Or to check if the key has been defined:
27
27
 
28
28
  UnifiedSettings.defined?('some_setting')
29
29
 
30
- This will search the following locations in the following order:
30
+ This will search for `some_setting` in the following locations in the following order:
31
31
  1. ENV
32
32
  2. Rails Credentials (if using Rails)
33
- 4. constants
33
+ 3. Constants
34
34
 
35
35
  When using `UnifiedSettings.get('some_setting')`, the *first* setting that matches the provided key will be returned. As such, even if the same key is defined in ENV, Credentials and as a constant, it will return the value defined in ENV as that is what will take precedence.
36
36
 
37
- If one wants to change the search order, or limit what is searched, one should provided the handlers to search explicity. For example:
37
+ If one wants to change the search order or limit what is searched, one should provide the handlers to search explicitly. For example:
38
38
 
39
39
  UnifiedSettings.get(
40
40
  'some_setting',
@@ -44,39 +44,39 @@ If one wants to change the search order, or limit what is searched, one should p
44
44
  ]
45
45
  )
46
46
 
47
- This will first search the Credentials, then ENV, and completely ignore any values that might be defined in Settings or as a constant. If there are any other places that need to be searched, a new custom handler can be created and then provided. To do this, just create a class that inherits from `UnifiedSettings::Handlers::Base` and add it to the list of handlers. For details on how to configure `UnifiedSettings` to use differnet handlers by default, see the Configuration section below.
47
+ This will first search the Credentials, then ENV, and completely ignore any values that might be defined in Settings or as a constant. If there are any other places that need to be searched, a new custom handler can be created and then provided. To do this, just create a class that inherits from `UnifiedSettings::Handlers::Base` and add it to the list of handlers. For details on how to configure `UnifiedSettings` to use different handlers by default, see the Configuration section below.
48
48
 
49
- Note, by default the search is also done in a "case insensitive" manner. This means, for each setting source, it will first try to match the key as provied (e.g. `Some_Setting`). If nothing is found it will then attempt an upper case version of the key (`SOME_SETTING`) and a lower case version (`some_setting`). If this is not desired, one can do
49
+ Note, by default the search is also done in a "case insensitive" manner. This means, that for each setting source, it will first try to match the key as provided (e.g. `Some_Setting`). If nothing is found it will then attempt an uppercase version of the key (`SOME_SETTING`) and a lowercase version (`some_setting`). If this is not desired, one can do
50
50
 
51
51
  UnifiedSettings.get('some_setting', case_sensitive: true)
52
52
 
53
53
  ### Predefined Handlers
54
54
 
55
- Build in are 4 pre-defined handlers that look for setting keys in predfined locattions
55
+ Built-in are 4 pre-defined handlers that look for setting keys in predefined locations
56
56
 
57
- * `UnifiedSettings::Handlers::ConfigGem`: Look for settings via the interface provied by [Config](https://github.com/rubyconfig/config)
57
+ * `UnifiedSettings::Handlers::ConfigGem`: Look for settings via the interface provided by [Config](https://github.com/rubyconfig/config)
58
58
  * `UnifiedSettings::Handlers::Constants`: Look for a setting defined by a constant
59
59
  * `UnifiedSettings::Handlers::Credentials`: Look for a setting in a Rails Credentials file
60
60
  * `UnifiedSettings::Handlers::Env`: Look for a setting defined in `ENV`
61
61
 
62
62
  ### Coercing strings to objects
63
63
 
64
- In many instances it is only possible to define strings as the value of a setting. For example, when setting an `ENV` var `SUPER_IMPORTANT_IDS` with the value of `1,2,3,4,5`, what the user really wants is a list of numbers, and not a comma separated string. As such, `UnifiedSettings` will automatically try to coerce things that look like arrays into arrays. Furthermore, it will convert things that look like floats to floats, ints to ints, booleans to booleans, etc. This way one does not have to worry about converting the values of settings to be easily used within the application. For example, is `some_setting` had the value of `' string, tRue, false,1, 2.2, NiL '`, the following be returned `['string', true, false, 1, 2.2, nil]`.
64
+ In many instances, it is only possible to define strings as the value of a setting. For example, when setting an `ENV` var `SUPER_IMPORTANT_IDS` with the value of `1,2,3,4,5`, what the user really wants is a list of numbers and not a comma-separated string. As such, `UnifiedSettings` will automatically try to coerce things that look like arrays into arrays. Furthermore, it will convert things that look like floats to floats, ints to ints, booleans to booleans, etc. This way one does not have to worry about converting the values of settings to be easily used within the application. For example, if `some_setting` had the value of `' string, tRue, false,1, 2.2, NiL '`, the following be returned `['string', true, false, 1, 2.2, nil]`.
65
65
 
66
- There are times when coercion is not desired (e.g. for things like long passcodes that may look like arrays since they may contain commas/numbers, etc.). For situations like this, simply disable the coercion.
66
+ There are times when coercion is not desired (e.g. for things like long passcodes that may look like arrays since they may contain commas/numbers, etc.). For situations like this, simply disable the coercion:
67
67
 
68
68
  UnifiedSettings.get(`some_setting`, coerce: false)
69
69
  ### Handling Missing Keys
70
70
 
71
71
  #### Setting a Default Value
72
72
 
73
- In many cases there might be a default value that should be provided if a key is missing. This can be supplied as follows:
73
+ In many cases, there might be a default value that should be provided if a key is missing. This can be supplied as follows:
74
74
 
75
75
  UnifiedSettings.get('some_setting', default: 'some_value')
76
76
 
77
77
  #### Logging/Raising Error
78
78
 
79
- By default, when there is a missing key, an message will be logged with the severity of `error`. Depending on the situation one may want a different behavior. As such, different error handlers can be passed to meet those needs. The following handlers are predefined: `:log_debug`, `:log_info`, `:log_warn`, `:log_error`, `:log_fatal`, `:raise`. For example:
79
+ By default, when there is a missing key, a message will be logged with the severity of `error`. Depending on the situation one may want a different behavior. As such, different error handlers can be passed to meet those needs. The following handlers are predefined: `:log_debug`, `:log_info`, `:log_warn`, `:log_error`, `:log_fatal`, `:raise`. For example:
80
80
 
81
81
  UnifiedSettings.get('some_setting', on_missing_key: :raise)
82
82
 
@@ -98,11 +98,11 @@ Furthermore, one can pass a list of hanlders, so that multiple things can happen
98
98
  ]
99
99
  )
100
100
 
101
- This will run the handlers in the order that they were defined.
101
+ This will run the handlers in the order they were defined.
102
102
 
103
103
  ### Nested Settings
104
104
 
105
- In many cases it is advantageous to have settings nested when defining them in, for example, the Rails Credentials file. For example, if we had the following defined in the Credentials file:
105
+ In many cases, it is advantageous to have settings nested when defining them in, for example, the Rails Credentials file. For example, if we had the following defined in the Credentials file:
106
106
 
107
107
  aws:
108
108
  client_id: SOME_ID
@@ -113,9 +113,9 @@ Then the corresponding setting keys would be:
113
113
  aws.client_id
114
114
  aws.client_secret
115
115
 
116
- As you can see, for nested settings, the convention to be used is to separate the elements using a '.'
116
+ As you can see, for nested settings, the convention to be used is to separate the elements using a '.' .
117
117
 
118
- The separator for ENV variables follow a slightly different as there can be issues when using a `.` in ENV variable names. As such the convention used in `UnifiedSettings` is modeled after the [Config gem](https://github.com/rubyconfig/config). When defining a value via an environment variable, the separator is a double underscore (`__`). Continuing with the above example, the ENV keys would be
118
+ The separator for ENV variables follows a slightly different way as there can be issues when using a `.` in ENV variable names. As such the convention used in `UnifiedSettings` is modeled after the [Config gem](https://github.com/rubyconfig/config). When defining a value via an environment variable, the separator is a double underscore (`__`). Continuing with the above example, the ENV keys would be
119
119
 
120
120
  AWS__CLIENT_ID
121
121
  AWS__CLIENT_SECRET
@@ -134,12 +134,12 @@ IMPORTANT FOR RAILS: If one is planning on using `UnifiedSettings` during the in
134
134
 
135
135
  ### Configuring the Handlers
136
136
 
137
- By default, the search order for a settings is:
137
+ By default, the search order for a setting is:
138
138
  1. ENV
139
139
  2. Rails Credentials (if using Rails)
140
- 4. constants
140
+ 3. Constants
141
141
 
142
- For example, if one is also using the [Config gem](https://github.com/rubyconfig/config), and would also like to search for settings there, one can add that handler.
142
+ For example, if one is using the [Config gem](https://github.com/rubyconfig/config), and would also like to search for settings there, one can add that handler.
143
143
 
144
144
  UnifiedSettings.configure do |config|
145
145
  config.handlers = [
@@ -150,7 +150,7 @@ For example, if one is also using the [Config gem](https://github.com/rubyconfig
150
150
  ]
151
151
  end
152
152
 
153
- If one needs to supply some extra parameters when initializing the handler, for example if a non-default constant is used for the `Config` gem, one needs only to pass a hash as follows:
153
+ If one needs to supply some extra parameters while initializing the handler, for example, if a non-default constant is used for the `Config` gem, one needs only to pass a hash as follows:
154
154
 
155
155
  UnifiedSettings.configure do |config|
156
156
  config.handlers = [
@@ -168,7 +168,7 @@ If one needs to supply some extra parameters when initializing the handler, for
168
168
 
169
169
  ### All Other Options
170
170
 
171
- Instead of going through all the various options, here is a fully worked out example with inline comments.
171
+ Instead of going through all the various options, here is a fully worked-out example with inline comments.
172
172
 
173
173
  ```
174
174
  UnifiedSettings.configure do |config|
@@ -191,7 +191,7 @@ UnifiedSettings.configure do |config|
191
191
  # UnifiedSettings.get('FOO.BAR.BAZ')
192
192
  # UnifiedSettings.get('foo.bar.bar')
193
193
  # UnifiedSettings.get('Foo.BaR.baZ')
194
- # If we set set case_sensitive = true, then only if the case exactly matches
194
+ # If we set case_sensitive = true, then only if the case exactly matches
195
195
  # the key is a result returned.
196
196
  # Default is: config.case_sensitive = false
197
197
  config.case_sensitive = false
@@ -206,12 +206,12 @@ UnifiedSettings.configure do |config|
206
206
  # ->(key) { puts "Something is wrong with #{key}" },
207
207
  # :raise
208
208
  # ]
209
- # This will run the handlers in the order that they were defined.
209
+ # This will run the handlers in the order they were defined.
210
210
  #
211
211
  # Default is: config.on_missing_key = :log_error
212
212
  config.on_missing_key = :log_error
213
213
 
214
- # The value that should be returned if no key was found. This can be a set
214
+ # The value that should be returned if no key was found. This can be set
215
215
  # to a particular value (e.g. `nil`, or `{}`), or can be an anonymous function
216
216
  # that takes `key` as a parameter. E.g.
217
217
  # config.default_value = ->(key) { key.starts_with?('a') ? 'AA' : 'ZZ'}
@@ -226,7 +226,7 @@ UnifiedSettings.configure do |config|
226
226
 
227
227
  # Whether or not to coerce strings that look like arrays to arrays.
228
228
  # E.g. "a, B, true,1 " would be coerced become to ["a", "B", true, 1]
229
- # Defualt is:
229
+ # Default is:
230
230
  # config.coerce_arrays = true
231
231
  # config.coerce_array_separator = ','
232
232
  config.coerce_arrays = true
@@ -246,4 +246,4 @@ Bug reports and pull requests are welcome on GitHub at https://github.com/prschm
246
246
 
247
247
  ## License
248
248
 
249
- The gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
249
+ This gem is available as open source under the terms of the [MIT License](https://opensource.org/licenses/MIT).
data/Rakefile CHANGED
@@ -4,13 +4,67 @@ require 'bundler/gem_tasks'
4
4
  require 'rake/testtask'
5
5
 
6
6
  Rake::TestTask.new(:test) do |t|
7
+ t.verbose = false
7
8
  t.libs << 'test'
8
9
  t.libs << 'lib'
9
- t.test_files = FileList['test/**/*_test.rb']
10
+ t.libs << 'test/dummy'
11
+
12
+ # We will include all of the files in test but are going to explicitly
13
+ # exclude all tests in rails. This is because we copy those files
14
+ # to the dummy Rails app so that we can test the Rails specific handlers
15
+ # in the context of a Rails app. See the `generate_dummy_rails_app` for
16
+ # more details
17
+ t.test_files =
18
+ FileList['test/**/*_test.rb'].exclude('test/rails/**/*_test.rb')
10
19
  end
11
20
 
12
- require 'rubocop/rake_task'
21
+ desc 'generate a dummy Rails app inside the test directory for testing purposes'
22
+ task :generate_dummy_rails_app do
23
+ if File.exist?('test/dummy/config/environment.rb')
24
+ FileUtils.rm_r Dir.glob('test/dummy/')
25
+ end
26
+
27
+ #
28
+ # Create a dummy rails app
29
+ #
30
+ system(
31
+ 'rails new test/dummy --skip-active-record ' \
32
+ '--skip-active-storage --skip-action-cable --skip-webpack-install ' \
33
+ '--skip-git --skip-sprockets --skip-javascript --skip-turbolinks'
34
+ )
35
+
36
+ # For now we don't need any DB specific things in our tests. However, if
37
+ # we ever do, we can update how we generate the rails app and then setup
38
+ # the DB appropriately using something like the following.
39
+ # system('rails new test/dummy --database=sqlite3')
40
+ # system('touch test/dummy/db/schema.rb')
41
+ # FileUtils.cp 'test/fixtures/database.yml', 'test/dummy/config/'
42
+
43
+ #
44
+ # Install/Setup the dependencies
45
+ #
46
+
47
+ system('cp -f test/rails/config/credentials.yml.enc test/dummy/config/.')
48
+ system('cp -f test/rails/config/master.key test/dummy/config/.')
49
+ system('cp -f test/rails/Gemfile test/dummy/.')
50
+ system('cp -f test/rails/.ruby-* test/dummy/.')
13
51
 
52
+ # Setup the Config gem
53
+ system('cd test/dummy; rails g config:install')
54
+ system(
55
+ 'cp test/rails/config/initializers/*.rb test/dummy/config/initializers/.'
56
+ )
57
+
58
+ #
59
+ # Setup the tests by deleting the existing Rails app tests and then copying
60
+ # our test over to the dummy app
61
+ #
62
+
63
+ FileUtils.rm_r Dir.glob('test/dummy/test/*')
64
+ system('cp -r test/rails/test/lib test/dummy/test/.')
65
+ end
66
+
67
+ require 'rubocop/rake_task'
14
68
  RuboCop::RakeTask.new
15
69
 
16
- task default: %i[test rubocop]
70
+ task default: %i[generate_dummy_rails_app test rubocop]
@@ -43,6 +43,8 @@ module UnifiedSettings
43
43
  end
44
44
 
45
45
  def nested_key_exists?(hash, keys)
46
+ return false if hash.nil?
47
+
46
48
  current_level = hash
47
49
  keys.each do |key|
48
50
  return false if current_level.nil?
@@ -50,6 +52,7 @@ module UnifiedSettings
50
52
 
51
53
  current_level = current_level[key]
52
54
  end
55
+
53
56
  false
54
57
  end
55
58
  end
@@ -37,6 +37,29 @@ module UnifiedSettings
37
37
 
38
38
  Rails.application.credentials.dig(*key_arr.map(&:upcase))
39
39
  end
40
+
41
+ protected
42
+
43
+ def nested_key_exists?(hash, keys)
44
+ if Rails.gem_version < Gem::Version.new('7.1.0')
45
+ super
46
+ else
47
+ return false if hash.nil?
48
+
49
+ # Rails 7.1 adds a key? method and so we need to get the config
50
+ # out of the credential object so that it can be treated as a hash
51
+ # https://github.com/rails/rails/blob/v7.1.1/activesupport/lib/active_support/encrypted_file.rb#L58-L60
52
+ current_level = hash.config
53
+ keys.each do |key|
54
+ return false if current_level.nil?
55
+ return true if current_level.key?(key)
56
+
57
+ current_level = current_level[key]
58
+ end
59
+
60
+ false
61
+ end
62
+ end
40
63
  end
41
64
  end
42
65
  end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UnifiedSettings
4
- VERSION = '0.1.1'
4
+ VERSION = '0.2.0'
5
5
  end
@@ -13,7 +13,15 @@ directories.each do |directory|
13
13
  end
14
14
  end
15
15
 
16
- ActiveRecord::Base.instance_eval { include UnifiedSettings }
16
+ begin
17
+ require 'active_record'
18
+ ActiveRecord::Base.instance_eval { include UnifiedSettings }
19
+ rescue LoadError => e
20
+ # rubocop:disable Rails/Output
21
+ puts "ERROR: Could not load active_record: #{e.message}"
22
+ # rubocop:enable Rails/Output
23
+ end
24
+
17
25
  if defined?(Rails) && Rails.version.to_i < 4
18
26
  raise 'This version of unified_settings requires Rails 4 or higher'
19
27
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: unified_settings
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.1.1
4
+ version: 0.2.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Patrick R. Schmid
8
8
  autorequire:
9
9
  bindir: exe
10
10
  cert_chain: []
11
- date: 2023-08-15 00:00:00.000000000 Z
11
+ date: 2024-12-04 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord
@@ -63,7 +63,6 @@ files:
63
63
  - lib/unified_settings/settings.rb
64
64
  - lib/unified_settings/unified_settings.rb
65
65
  - lib/unified_settings/version.rb
66
- - unified_settings.gemspec
67
66
  homepage: https://github.com/prschmid/unified_settings
68
67
  licenses:
69
68
  - MIT
@@ -80,14 +79,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
80
79
  requirements:
81
80
  - - ">="
82
81
  - !ruby/object:Gem::Version
83
- version: '3.2'
82
+ version: '3.3'
84
83
  required_rubygems_version: !ruby/object:Gem::Requirement
85
84
  requirements:
86
85
  - - ">="
87
86
  - !ruby/object:Gem::Version
88
87
  version: '0'
89
88
  requirements: []
90
- rubygems_version: 3.4.10
89
+ rubygems_version: 3.5.22
91
90
  signing_key:
92
91
  specification_version: 4
93
92
  summary: A unified way to get settings from different sources.
@@ -1,46 +0,0 @@
1
- # frozen_string_literal: true
2
-
3
- lib = File.expand_path('lib', __dir__)
4
- $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
5
- require 'unified_settings/version'
6
-
7
- Gem::Specification.new do |spec|
8
- spec.name = 'unified_settings'
9
- spec.version = UnifiedSettings::VERSION
10
- spec.authors = ['Patrick R. Schmid']
11
- spec.email = ['prschmid@gmail.com']
12
-
13
- spec.summary = 'A unified way to get settings from different sources.'
14
- spec.description = 'A unified way to get settings from different sources.'
15
- spec.homepage = 'https://github.com/prschmid/unified_settings'
16
- spec.license = 'MIT'
17
-
18
- # Prevent pushing this gem to RubyGems.org. To allow pushes either set the
19
- # 'allowed_push_host' to allow pushing to a single host or delete this
20
- # section to allow pushing to any host.
21
- if spec.respond_to?(:metadata)
22
- spec.metadata['homepage_uri'] = spec.homepage
23
- spec.metadata['source_code_uri'] = 'https://github.com/prschmid/unified_settings'
24
- spec.metadata['changelog_uri'] = 'https://github.com/prschmid/unified_settings'
25
- else
26
- raise 'RubyGems 2.0 or newer is required to protect against ' \
27
- 'public gem pushes.'
28
- end
29
-
30
- # Specify which files should be added to the gem when it is released.
31
- # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
32
- spec.files = Dir.chdir(__dir__) do
33
- `git ls-files -z`.split("\x0").reject do |f|
34
- (f == __FILE__) || f.match(%r{\A(?:(?:bin|test|spec|features)/|\.(?:git|travis|circleci)|appveyor)})
35
- end
36
- end
37
- spec.bindir = 'exe'
38
- spec.executables = spec.files.grep(%r{\Aexe/}) { |f| File.basename(f) }
39
- spec.require_paths = ['lib']
40
-
41
- spec.required_ruby_version = '>= 3.2'
42
-
43
- spec.add_runtime_dependency('activerecord', '> 4.2.0')
44
- spec.add_runtime_dependency('activesupport', '> 4.2.0')
45
- spec.metadata['rubygems_mfa_required'] = 'true'
46
- end