unified_settings 0.1.0 → 0.1.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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cc523c80caf34cfc9c862df454f01a434518c149e94ef342d354c7f5af4e40fe
4
- data.tar.gz: 42e5d82f9d6b6cb4ee87b49c0ef97c987176bbb688a4f8b2492f6f4f353ff509
3
+ metadata.gz: 597e3217c2958d077da18c870c58d575fef381dbc7cea33543b91ed8eb1acb12
4
+ data.tar.gz: 2e724e7b2f9e0d91dac7096c9b7b4ec470b0e843da9721b3239b2c279abef6db
5
5
  SHA512:
6
- metadata.gz: d7ead0fae11ea90725007c1b0c8d80c309ad12fe2e25b86181355502efca95631992ffbbee21c8416228b65937238bae242c76ddb170771f5169ca229d3567ec
7
- data.tar.gz: 96a5d214ba297bee6f0cbc0e8309a34ab30a85ad4d87c91d8941ab06b17954341d6b4bbb0416850f327f642922b32bc3b352908520d778fc9296a571dc78a7d7
6
+ metadata.gz: 406732e761a985303996246a2e5eac68fe54c0f732914fc5bcaea8ab2dfb4c0f6f3b726ef989c7c014d6f68856d56d955a7b22ccceb2af349cd5030699e85227
7
+ data.tar.gz: fee4bb0449050da1cb17975dc75d2e9b825131280148e5fa6e6627da35f1861228754eb61e3c5fa0c13f29e9eefad9679e6840aabb0bb5ac70be12c4ffad1fc5
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/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,74 @@ 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', '~> 7.0.7', '>= 7.0.7.2'
25
+
26
+ # The original asset pipeline for Rails
27
+ # [https://github.com/rails/sprockets-rails]
28
+ gem 'sprockets-rails'
29
+
30
+ # Use the Puma web server
31
+ # [https://github.com/puma/puma]
32
+ gem 'puma', '~> 5.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
+ # Use Sass to process CSS
53
+ # gem "sassc-rails"
54
+
55
+ group :development, :test do
56
+ # See https://guides.rubyonrails.org/debugging_rails_applications.html#debugging-with-the-debug-gem
57
+ gem 'debug', platforms: %i[mri mingw x64_mingw]
58
+ end
59
+
60
+ group :development do
61
+ # Use console on exceptions pages [https://github.com/rails/web-console]
62
+ # gem 'web-console'
63
+
64
+ # Add speed badges [https://github.com/MiniProfiler/rack-mini-profiler]
65
+ # gem "rack-mini-profiler"
66
+
67
+ # Speed up commands on slow machines / big apps
68
+ # [https://github.com/rails/spring]
69
+ # gem "spring"
70
+ end
71
+
72
+ group :test do
73
+ # Use system testing
74
+ # [https://guides.rubyonrails.org/testing.html#system-testing]
75
+ gem 'capybara'
76
+ gem 'selenium-webdriver'
77
+ gem 'webdrivers'
78
+ end
79
+
80
+ #
81
+ # Gem that has been added to default Gemfile so that we can run the tests
82
+ # for the handlers
83
+ #
84
+
85
+ #
86
+ # Add multi-environment yaml settings to rails
87
+ # https://github.com/rubyconfig/config
88
+ gem 'config', '>= 3.0'
data/Gemfile.lock CHANGED
@@ -1,36 +1,110 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- unified_settings (0.1.0)
4
+ unified_settings (0.1.2)
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.6)
12
- activesupport (= 7.0.6)
13
- activerecord (7.0.6)
14
- activemodel (= 7.0.6)
15
- activesupport (= 7.0.6)
16
- activesupport (7.0.6)
11
+ actioncable (7.0.8)
12
+ actionpack (= 7.0.8)
13
+ activesupport (= 7.0.8)
14
+ nio4r (~> 2.0)
15
+ websocket-driver (>= 0.6.1)
16
+ actionmailbox (7.0.8)
17
+ actionpack (= 7.0.8)
18
+ activejob (= 7.0.8)
19
+ activerecord (= 7.0.8)
20
+ activestorage (= 7.0.8)
21
+ activesupport (= 7.0.8)
22
+ mail (>= 2.7.1)
23
+ net-imap
24
+ net-pop
25
+ net-smtp
26
+ actionmailer (7.0.8)
27
+ actionpack (= 7.0.8)
28
+ actionview (= 7.0.8)
29
+ activejob (= 7.0.8)
30
+ activesupport (= 7.0.8)
31
+ mail (~> 2.5, >= 2.5.4)
32
+ net-imap
33
+ net-pop
34
+ net-smtp
35
+ rails-dom-testing (~> 2.0)
36
+ actionpack (7.0.8)
37
+ actionview (= 7.0.8)
38
+ activesupport (= 7.0.8)
39
+ rack (~> 2.0, >= 2.2.4)
40
+ rack-test (>= 0.6.3)
41
+ rails-dom-testing (~> 2.0)
42
+ rails-html-sanitizer (~> 1.0, >= 1.2.0)
43
+ actiontext (7.0.8)
44
+ actionpack (= 7.0.8)
45
+ activerecord (= 7.0.8)
46
+ activestorage (= 7.0.8)
47
+ activesupport (= 7.0.8)
48
+ globalid (>= 0.6.0)
49
+ nokogiri (>= 1.8.5)
50
+ actionview (7.0.8)
51
+ activesupport (= 7.0.8)
52
+ builder (~> 3.1)
53
+ erubi (~> 1.4)
54
+ rails-dom-testing (~> 2.0)
55
+ rails-html-sanitizer (~> 1.1, >= 1.2.0)
56
+ activejob (7.0.8)
57
+ activesupport (= 7.0.8)
58
+ globalid (>= 0.3.6)
59
+ activemodel (7.0.8)
60
+ activesupport (= 7.0.8)
61
+ activerecord (7.0.8)
62
+ activemodel (= 7.0.8)
63
+ activesupport (= 7.0.8)
64
+ activestorage (7.0.8)
65
+ actionpack (= 7.0.8)
66
+ activejob (= 7.0.8)
67
+ activerecord (= 7.0.8)
68
+ activesupport (= 7.0.8)
69
+ marcel (~> 1.0)
70
+ mini_mime (>= 1.1.0)
71
+ activesupport (7.0.8)
17
72
  concurrent-ruby (~> 1.0, >= 1.0.2)
18
73
  i18n (>= 1.6, < 2)
19
74
  minitest (>= 5.1)
20
75
  tzinfo (~> 2.0)
76
+ addressable (2.8.5)
77
+ public_suffix (>= 2.0.2, < 6.0)
21
78
  ast (2.4.2)
79
+ bootsnap (1.17.0)
80
+ msgpack (~> 1.2)
81
+ builder (3.2.4)
22
82
  bundler-audit (0.9.1)
23
83
  bundler (>= 1.2.0, < 3)
24
84
  thor (~> 1.0)
85
+ capybara (3.39.2)
86
+ addressable
87
+ matrix
88
+ mini_mime (>= 0.1.3)
89
+ nokogiri (~> 1.8)
90
+ rack (>= 1.6.0)
91
+ rack-test (>= 0.6.3)
92
+ regexp_parser (>= 1.5, < 3.0)
93
+ xpath (~> 3.2)
25
94
  concurrent-ruby (1.2.2)
26
- config (4.2.1)
95
+ config (5.0.0)
27
96
  deep_merge (~> 1.2, >= 1.2.1)
28
97
  dry-validation (~> 1.0, >= 1.0.0)
98
+ crass (1.0.6)
99
+ date (3.3.3)
100
+ debug (1.8.0)
101
+ irb (>= 1.5.0)
102
+ reline (>= 0.3.1)
29
103
  deep_merge (1.2.2)
30
- dry-configurable (1.0.1)
104
+ dry-configurable (1.1.0)
31
105
  dry-core (~> 1.0, < 2)
32
106
  zeitwerk (~> 2.6)
33
- dry-core (1.0.0)
107
+ dry-core (1.0.1)
34
108
  concurrent-ruby (~> 1.0)
35
109
  zeitwerk (~> 2.6)
36
110
  dry-inflector (1.0.0)
@@ -39,7 +113,7 @@ GEM
39
113
  concurrent-ruby (~> 1.0)
40
114
  dry-core (~> 1.0, < 2)
41
115
  zeitwerk (~> 2.6)
42
- dry-schema (1.13.2)
116
+ dry-schema (1.13.3)
43
117
  concurrent-ruby (~> 1.0)
44
118
  dry-configurable (~> 1.0, >= 1.0.1)
45
119
  dry-core (~> 1.0, < 2)
@@ -59,40 +133,113 @@ GEM
59
133
  dry-initializer (~> 3.0)
60
134
  dry-schema (>= 1.12, < 2)
61
135
  zeitwerk (~> 2.6)
136
+ erubi (1.12.0)
137
+ globalid (1.2.1)
138
+ activesupport (>= 6.1)
62
139
  i18n (1.14.1)
63
140
  concurrent-ruby (~> 1.0)
141
+ io-console (0.6.0)
142
+ irb (1.8.3)
143
+ rdoc
144
+ reline (>= 0.3.8)
64
145
  json (2.6.3)
65
146
  language_server-protocol (3.17.0.3)
66
- minitest (5.18.1)
147
+ loofah (2.21.4)
148
+ crass (~> 1.0.2)
149
+ nokogiri (>= 1.12.0)
150
+ mail (2.8.1)
151
+ mini_mime (>= 0.1.1)
152
+ net-imap
153
+ net-pop
154
+ net-smtp
155
+ marcel (1.0.2)
156
+ matrix (0.4.2)
157
+ method_source (1.0.0)
158
+ mini_mime (1.1.5)
159
+ minitest (5.20.0)
160
+ msgpack (1.7.2)
161
+ net-imap (0.4.3)
162
+ date
163
+ net-protocol
164
+ net-pop (0.1.2)
165
+ net-protocol
166
+ net-protocol (0.2.1)
167
+ timeout
168
+ net-smtp (0.4.0)
169
+ net-protocol
170
+ nio4r (2.5.9)
171
+ nokogiri (1.15.4-x86_64-darwin)
172
+ racc (~> 1.4)
173
+ nokogiri (1.15.4-x86_64-linux)
174
+ racc (~> 1.4)
67
175
  parallel (1.23.0)
68
- parser (3.2.2.3)
176
+ parser (3.2.2.4)
69
177
  ast (~> 2.4.1)
70
178
  racc
179
+ psych (5.1.1.1)
180
+ stringio
181
+ public_suffix (5.0.3)
182
+ puma (5.6.7)
183
+ nio4r (~> 2.0)
71
184
  racc (1.7.1)
72
- rack (2.2.7)
185
+ rack (2.2.8)
186
+ rack-test (2.1.0)
187
+ rack (>= 1.3)
188
+ rails (7.0.8)
189
+ actioncable (= 7.0.8)
190
+ actionmailbox (= 7.0.8)
191
+ actionmailer (= 7.0.8)
192
+ actionpack (= 7.0.8)
193
+ actiontext (= 7.0.8)
194
+ actionview (= 7.0.8)
195
+ activejob (= 7.0.8)
196
+ activemodel (= 7.0.8)
197
+ activerecord (= 7.0.8)
198
+ activestorage (= 7.0.8)
199
+ activesupport (= 7.0.8)
200
+ bundler (>= 1.15.0)
201
+ railties (= 7.0.8)
202
+ rails-dom-testing (2.2.0)
203
+ activesupport (>= 5.0.0)
204
+ minitest
205
+ nokogiri (>= 1.6)
206
+ rails-html-sanitizer (1.6.0)
207
+ loofah (~> 2.21)
208
+ nokogiri (~> 1.14)
209
+ railties (7.0.8)
210
+ actionpack (= 7.0.8)
211
+ activesupport (= 7.0.8)
212
+ method_source
213
+ rake (>= 12.2)
214
+ thor (~> 1.0)
215
+ zeitwerk (~> 2.5)
73
216
  rainbow (3.1.1)
74
- rake (13.0.6)
75
- regexp_parser (2.8.1)
76
- rexml (3.2.5)
77
- rubocop (1.54.2)
217
+ rake (13.1.0)
218
+ rdoc (6.5.0)
219
+ psych (>= 4.0.0)
220
+ regexp_parser (2.8.2)
221
+ reline (0.3.9)
222
+ io-console (~> 0.5)
223
+ rexml (3.2.6)
224
+ rubocop (1.57.2)
78
225
  json (~> 2.3)
79
226
  language_server-protocol (>= 3.17.0)
80
227
  parallel (~> 1.10)
81
- parser (>= 3.2.2.3)
228
+ parser (>= 3.2.2.4)
82
229
  rainbow (>= 2.2.2, < 4.0)
83
230
  regexp_parser (>= 1.8, < 3.0)
84
231
  rexml (>= 3.2.5, < 4.0)
85
- rubocop-ast (>= 1.28.0, < 2.0)
232
+ rubocop-ast (>= 1.28.1, < 2.0)
86
233
  ruby-progressbar (~> 1.7)
87
234
  unicode-display_width (>= 2.4.0, < 3.0)
88
- rubocop-ast (1.29.0)
235
+ rubocop-ast (1.30.0)
89
236
  parser (>= 3.2.1.0)
90
- rubocop-minitest (0.31.0)
237
+ rubocop-minitest (0.33.0)
91
238
  rubocop (>= 1.39, < 2.0)
92
- rubocop-performance (1.18.0)
239
+ rubocop-performance (1.19.1)
93
240
  rubocop (>= 1.7.0, < 2.0)
94
241
  rubocop-ast (>= 0.4.0)
95
- rubocop-rails (2.20.2)
242
+ rubocop-rails (2.22.1)
96
243
  activesupport (>= 4.2.0)
97
244
  rack (>= 1.1)
98
245
  rubocop (>= 1.33.0, < 2.0)
@@ -101,21 +248,50 @@ GEM
101
248
  ruby-progressbar (1.13.0)
102
249
  ruby_audit (2.2.0)
103
250
  bundler-audit (~> 0.9.0)
104
- thor (1.2.2)
251
+ rubyzip (2.3.2)
252
+ selenium-webdriver (4.10.0)
253
+ rexml (~> 3.2, >= 3.2.5)
254
+ rubyzip (>= 1.2.2, < 3.0)
255
+ websocket (~> 1.0)
256
+ sprockets (4.2.1)
257
+ concurrent-ruby (~> 1.0)
258
+ rack (>= 2.2.4, < 4)
259
+ sprockets-rails (3.4.2)
260
+ actionpack (>= 5.2)
261
+ activesupport (>= 5.2)
262
+ sprockets (>= 3.0.0)
263
+ stringio (3.0.8)
264
+ thor (1.3.0)
265
+ timeout (0.4.0)
105
266
  tzinfo (2.0.6)
106
267
  concurrent-ruby (~> 1.0)
107
- unicode-display_width (2.4.2)
108
- zeitwerk (2.6.8)
268
+ unicode-display_width (2.5.0)
269
+ webdrivers (5.3.1)
270
+ nokogiri (~> 1.6)
271
+ rubyzip (>= 1.3.0)
272
+ selenium-webdriver (~> 4.0, < 4.11)
273
+ websocket (1.2.10)
274
+ websocket-driver (0.7.6)
275
+ websocket-extensions (>= 0.1.0)
276
+ websocket-extensions (0.1.5)
277
+ xpath (3.2.0)
278
+ nokogiri (~> 1.8)
279
+ zeitwerk (2.6.12)
109
280
 
110
281
  PLATFORMS
111
282
  x86_64-darwin-22
112
283
  x86_64-linux
113
284
 
114
285
  DEPENDENCIES
286
+ bootsnap
115
287
  bundler (~> 2.3)
116
288
  bundler-audit
289
+ capybara
117
290
  config (>= 3.0)
291
+ debug
118
292
  minitest (~> 5.0)
293
+ puma (~> 5.0)
294
+ rails (~> 7.0.7, >= 7.0.7.2)
119
295
  rake (~> 13.0)
120
296
  rubocop (~> 1.21)
121
297
  rubocop-minitest
@@ -123,7 +299,11 @@ DEPENDENCIES
123
299
  rubocop-rails
124
300
  rubocop-rake
125
301
  ruby_audit
302
+ selenium-webdriver
303
+ sprockets-rails
304
+ tzinfo-data
126
305
  unified_settings!
306
+ webdrivers
127
307
 
128
308
  BUNDLED WITH
129
309
  2.4.10
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,64 @@ 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/Gemfile test/dummy/.')
13
48
 
49
+ # Setup the Config gem
50
+ system('cd test/dummy; rails g config:install')
51
+ system(
52
+ 'cp test/rails/config/initializers/*.rb test/dummy/config/initializers/.'
53
+ )
54
+
55
+ #
56
+ # Setup the tests by deleting the existing Rails app tests and then copying
57
+ # our test over to the dummy app
58
+ #
59
+
60
+ FileUtils.rm_r Dir.glob('test/dummy/test/*')
61
+ system('cp -r test/rails/test/lib test/dummy/test/.')
62
+ end
63
+
64
+ require 'rubocop/rake_task'
14
65
  RuboCop::RakeTask.new
15
66
 
16
- task default: %i[test rubocop]
67
+ 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
@@ -32,11 +32,11 @@ module UnifiedSettings
32
32
  case_sensitive = case_sensitive?(case_sensitive)
33
33
 
34
34
  val = setting_obj.dig(*key_arr)
35
- return val if val
35
+ return val unless val.nil?
36
36
  return nil if case_sensitive
37
37
 
38
38
  val = setting_obj.dig(*key_arr.map(&:downcase))
39
- return val if val
39
+ return val unless val.nil?
40
40
 
41
41
  setting_obj.dig(*key_arr.map(&:upcase))
42
42
  end
@@ -15,8 +15,8 @@ module UnifiedSettings
15
15
 
16
16
  variable_names.each do |name|
17
17
  if klass
18
- return true if klass.const_get(name)
19
- elsif Object.const_get(name)
18
+ return true if klass.const_defined?(name)
19
+ elsif Object.const_defined?(name)
20
20
  return true
21
21
  end
22
22
  rescue NameError
@@ -29,14 +29,37 @@ module UnifiedSettings
29
29
  case_sensitive = case_sensitive?(case_sensitive)
30
30
 
31
31
  val = Rails.application.credentials.dig(*key_arr)
32
- return val if val
32
+ return val unless val.nil?
33
33
  return nil if case_sensitive
34
34
 
35
35
  val = Rails.application.credentials.dig(*key_arr.map(&:downcase))
36
- return val if val
36
+ return val unless val.nil?
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.0'
4
+ VERSION = '0.1.2'
5
5
  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.0
4
+ version: 0.1.2
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-07-16 00:00:00.000000000 Z
11
+ date: 2023-10-31 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord