anyway_config 2.0.6 → 2.1.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/CHANGELOG.md +199 -181
- data/README.md +69 -9
- data/lib/.rbnext/1995.next/anyway/config.rb +391 -0
- data/lib/.rbnext/1995.next/anyway/dynamic_config.rb +27 -0
- data/lib/.rbnext/1995.next/anyway/env.rb +56 -0
- data/lib/.rbnext/1995.next/anyway/loaders/base.rb +21 -0
- data/lib/.rbnext/1995.next/anyway/tracing.rb +181 -0
- data/lib/.rbnext/2.7/anyway/config.rb +12 -14
- data/lib/.rbnext/2.7/anyway/rails/loaders/yaml.rb +30 -0
- data/lib/.rbnext/2.7/anyway/settings.rb +79 -0
- data/lib/.rbnext/2.7/anyway/tracing.rb +8 -6
- data/lib/.rbnext/{2.8 → 3.0}/anyway/config.rb +12 -14
- data/lib/.rbnext/{2.8 → 3.0}/anyway/loaders.rb +0 -0
- data/lib/.rbnext/{2.8 → 3.0}/anyway/loaders/base.rb +0 -0
- data/lib/.rbnext/{2.8 → 3.0}/anyway/tracing.rb +8 -6
- data/lib/anyway/config.rb +26 -28
- data/lib/anyway/dynamic_config.rb +1 -1
- data/lib/anyway/env.rb +1 -1
- data/lib/anyway/ext/deep_dup.rb +6 -0
- data/lib/anyway/ext/hash.rb +0 -12
- data/lib/anyway/loaders/base.rb +1 -1
- data/lib/anyway/loaders/yaml.rb +3 -3
- data/lib/anyway/rails/loaders/credentials.rb +2 -2
- data/lib/anyway/rails/loaders/secrets.rb +1 -1
- data/lib/anyway/rails/loaders/yaml.rb +11 -0
- data/lib/anyway/rails/settings.rb +6 -0
- data/lib/anyway/settings.rb +52 -2
- data/lib/anyway/tracing.rb +4 -4
- data/lib/anyway/utils/deep_merge.rb +21 -0
- data/lib/anyway/version.rb +1 -1
- data/lib/anyway_config.rb +2 -0
- metadata +18 -10
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ae67246988f82692f84ae07b01642fbca38c9f1593b0e4292b335e08654bbf7e
|
4
|
+
data.tar.gz: 045f36927093f3e7929889918dff12d63c61ef58ffcb5fc5793f017dd2da1c5e
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: de0f8281daad0d2da4ad557f7099602a46d7fa4476f0a3adfb5b7f14c3abcd44fd020a89fd661a4c9ebeb9b5e70550d37f1b16d01bf68d535ab63877b9ae1661
|
7
|
+
data.tar.gz: 04de1b39c49b4dc39faa12ee199143ca64b3722cbc547e8c41b41bc3e7e365848bae2f06dfc9f99db5693782df4239cd5bbdca99cf2e58e50f38147b2b5dc95e
|
data/CHANGELOG.md
CHANGED
@@ -1,5 +1,37 @@
|
|
1
1
|
# Change log
|
2
2
|
|
3
|
+
## master
|
4
|
+
|
5
|
+
## 2.1.0 (2020-12-29)
|
6
|
+
|
7
|
+
- Drop deprecated `attr_config` instance variables support.
|
8
|
+
|
9
|
+
Config setters no longer write instance variables.
|
10
|
+
|
11
|
+
- Add `config.anyway_config.future` to allow enabling upcoming features. ([@palkan][])
|
12
|
+
|
13
|
+
For smoother upgrades, we provide a mechanism to opt-out to the new defaults beforehand.
|
14
|
+
Currently, only `:unwrap_known_environments` feature could be enabled (see below):
|
15
|
+
|
16
|
+
```ruby
|
17
|
+
config.anyway_config.future.use :unwrap_known_environments
|
18
|
+
```
|
19
|
+
|
20
|
+
- Allow to skip environment keys completely (e.g., `development:`, `test:`) in a config YML when used with Rails. In that case same config is loaded in all known environments (same mechanism as for non-Rails applications)
|
21
|
+
|
22
|
+
- Add the `known_environments` property to Anyway::Settings under Rails. Use `config.anyway_config.known_environments << "staging"` to make the gem aware of custom environments. ([@progapandist][])
|
23
|
+
|
24
|
+
- Make it possible to specify default YML configs directory. ([@palkan][])
|
25
|
+
|
26
|
+
For example:
|
27
|
+
|
28
|
+
```ruby
|
29
|
+
Anyway::Settings.default_config_path = "path/to/configs"
|
30
|
+
|
31
|
+
# or in Rails
|
32
|
+
config.anyway_config.default_config_path = Rails.root.join("my/configs")
|
33
|
+
```
|
34
|
+
|
3
35
|
## 2.0.6 (2020-07-7)
|
4
36
|
|
5
37
|
- Fix Ruby 2.7 warnings. ([@palkan][])
|
@@ -20,13 +52,13 @@
|
|
20
52
|
|
21
53
|
- Make sure configs are eager loaded in Rails when `config.eager_load = true`. ([@palkan][])
|
22
54
|
|
23
|
-
|
55
|
+
Fixes [#58](https://github.com/palkan/anyway_config/issues/58).
|
24
56
|
|
25
57
|
## 2.0.1 (2020-04-15)
|
26
58
|
|
27
59
|
- Fix loading Railtie when application has been already initialized. ([@palkan][])
|
28
60
|
|
29
|
-
|
61
|
+
Fixes [#56](https://github.com/palkan/anyway_config/issues/56).
|
30
62
|
|
31
63
|
## 2.0.0 (2020-04-14)
|
32
64
|
|
@@ -36,166 +68,166 @@
|
|
36
68
|
|
37
69
|
- Add predicate methods for attributes with boolean defaults. ([@palkan][])
|
38
70
|
|
39
|
-
|
71
|
+
For example:
|
40
72
|
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
73
|
+
```ruby
|
74
|
+
class MyConfig < Anyway::Config
|
75
|
+
attr_config :key, :secret, debug: false
|
76
|
+
end
|
45
77
|
|
46
|
-
|
47
|
-
|
48
|
-
|
78
|
+
MyConfig.new.debug? #=> false
|
79
|
+
MyConfig.new(debug: true).debug? #=> true
|
80
|
+
```
|
49
81
|
|
50
82
|
- Add `Config#deconstruct_keys`. ([@palkan][])
|
51
83
|
|
52
|
-
|
84
|
+
Now you can use configs in pattern matching:
|
53
85
|
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
86
|
+
```ruby
|
87
|
+
case AWSConfig.new
|
88
|
+
in bucket:, region: "eu-west-1"
|
89
|
+
setup_eu_storage(bucket)
|
90
|
+
in bucket:, region: "us-east-1"
|
91
|
+
setup_us_storage(bucket)
|
92
|
+
end
|
93
|
+
```
|
62
94
|
|
63
95
|
- Add pretty_print support. ([@palkan][])
|
64
96
|
|
65
|
-
|
66
|
-
|
97
|
+
Whenever you use `pp`, the output would contain pretty formatted config information
|
98
|
+
including the sources.
|
67
99
|
|
68
|
-
|
100
|
+
Example:
|
69
101
|
|
70
|
-
|
71
|
-
|
102
|
+
```ruby
|
103
|
+
pp CoolConfig.new
|
72
104
|
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
105
|
+
# #<CoolConfig
|
106
|
+
# config_name="cool"
|
107
|
+
# env_prefix="COOL"
|
108
|
+
# values:
|
109
|
+
# port => 3334 (type=load),
|
110
|
+
# host => "test.host" (type=yml path=./config/cool.yml),
|
111
|
+
# user =>
|
112
|
+
# name => "john" (type=env key=COOL_USER__NAME),
|
113
|
+
# password => "root" (type=yml path=./config/cool.yml)>
|
114
|
+
```
|
83
115
|
|
84
116
|
- Add source tracing support. ([@palkan][])
|
85
117
|
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
98
|
-
|
99
|
-
|
100
|
-
|
118
|
+
You can get the information on where a particular parameter value came from
|
119
|
+
(which loader) through via `#to_source_trace` method:
|
120
|
+
|
121
|
+
```ruby
|
122
|
+
conf = MyConfig.new
|
123
|
+
conf.to_source_trace
|
124
|
+
# {
|
125
|
+
# "host" => {value: "test.host", source: {type: :user, called_from: "/rails/root/config/application.rb:21"}},
|
126
|
+
# "user" => {
|
127
|
+
# "name" => {value: "john", source: {type: :env, key: "COOL_USER__NAME"}},
|
128
|
+
# "password" => {value: "root", source: {type: :yml, path: "config/cool.yml"}}
|
129
|
+
# },
|
130
|
+
# "port" => {value: 9292, source: {type: :defaults}}
|
131
|
+
# }
|
132
|
+
```
|
101
133
|
|
102
134
|
- Change the way Rails configs autoloading works. ([@palkan][])
|
103
135
|
|
104
|
-
|
105
|
-
|
136
|
+
In Rails 6, autoloading before initialization is [deprecated](https://github.com/rails/rails/commit/3e66ba91d511158e22f90ff96b594d61f40eda01). We can still
|
137
|
+
make it work by using our own autoloading mechanism (custom Zeitwerk loader).
|
106
138
|
|
107
|
-
|
108
|
-
|
109
|
-
|
139
|
+
This forces us to use a custom directory (not `app/`) for configs required at the boot time.
|
140
|
+
By default, we put _static_ configs into `config/configs` but you can still use `app/configs` for
|
141
|
+
_dynamic_ (runtime) configs.
|
110
142
|
|
111
|
-
|
112
|
-
|
143
|
+
**NOTE:** if you used `app/configs` with 2.0.0.preX and relied on configs during initialization,
|
144
|
+
you can set static configs path to `app/configs`:
|
113
145
|
|
114
|
-
|
115
|
-
|
116
|
-
|
146
|
+
```ruby
|
147
|
+
config.anyway_config.autoload_static_config_path = "app/configs"
|
148
|
+
```
|
117
149
|
|
118
|
-
|
150
|
+
You can do this by running the generator:
|
119
151
|
|
120
|
-
|
121
|
-
|
122
|
-
|
152
|
+
```sh
|
153
|
+
rails g anyway:install --configs-path=app/configs
|
154
|
+
```
|
123
155
|
|
124
156
|
- Add Rails generators. ([@palkan][])
|
125
157
|
|
126
|
-
|
158
|
+
You can create config classes with the predefined attributes like this:
|
127
159
|
|
128
|
-
|
129
|
-
|
130
|
-
|
160
|
+
```sh
|
161
|
+
rails generate config aws access_key_id secret_access_key region
|
162
|
+
```
|
131
163
|
|
132
164
|
- **BREAKING** The accessors generated by `attr_config` are not longer `attr_accessor`-s. ([@palkan][])
|
133
165
|
|
134
|
-
|
135
|
-
|
166
|
+
You cannot rely on instance variables anymore. Instead, you can use `super` when overriding accessors or
|
167
|
+
`values[name]`:
|
136
168
|
|
137
|
-
|
138
|
-
|
169
|
+
```ruby
|
170
|
+
attr_config :host, :port, :url, :meta
|
139
171
|
|
140
|
-
|
141
|
-
|
142
|
-
|
143
|
-
|
172
|
+
# override writer to handle type coercion
|
173
|
+
def meta=(val)
|
174
|
+
super JSON.parse(val)
|
175
|
+
end
|
144
176
|
|
145
|
-
|
146
|
-
|
147
|
-
|
148
|
-
|
177
|
+
# or override reader to handle missing values
|
178
|
+
def url
|
179
|
+
values[:url] ||= "#{host}:#{port}"
|
180
|
+
end
|
149
181
|
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
182
|
+
# in <2.1 it's still possible to read instance variables,
|
183
|
+
# i.e. the following would also work
|
184
|
+
def url
|
185
|
+
@url ||= "#{host}:#{port}"
|
186
|
+
end
|
187
|
+
```
|
156
188
|
|
157
|
-
|
158
|
-
|
189
|
+
**NOTE**: we still set instance variables in writers (for backward compatibility), but that would
|
190
|
+
be removed in 2.1.
|
159
191
|
|
160
192
|
- Add `Config#dig` method. ([@palkan][])
|
161
193
|
|
162
194
|
- Add ability to specify types for OptionParser options. ([@palkan][])
|
163
195
|
|
164
|
-
|
165
|
-
|
166
|
-
|
167
|
-
|
168
|
-
|
169
|
-
|
170
|
-
|
171
|
-
|
196
|
+
```ruby
|
197
|
+
describe_options(
|
198
|
+
concurrency: {
|
199
|
+
desc: "number of threads to use",
|
200
|
+
type: String
|
201
|
+
}
|
202
|
+
)
|
203
|
+
```
|
172
204
|
|
173
205
|
- Add param presence validation. ([@palkan][])
|
174
206
|
|
175
|
-
|
176
|
-
|
207
|
+
You can specify some params as required, and the validation
|
208
|
+
error would be raised if they're missing or empty (only for strings):
|
177
209
|
|
178
|
-
|
179
|
-
|
180
|
-
|
210
|
+
```ruby
|
211
|
+
class MyConfig < Anyway::Config
|
212
|
+
attr_config :api_key, :api_secret, :debug
|
181
213
|
|
182
|
-
|
183
|
-
|
214
|
+
required :api_key, :api_secret
|
215
|
+
end
|
184
216
|
|
185
|
-
|
186
|
-
|
217
|
+
MyConfig.new(api_secret: "") #=> raises Anyway::Config::ValidationError
|
218
|
+
```
|
187
219
|
|
188
|
-
|
220
|
+
You can change the validation behaviour by overriding the `#validate!` method in your config class.
|
189
221
|
|
190
222
|
- Validate config attribute names. ([@palkan][])
|
191
223
|
|
192
|
-
|
193
|
-
|
224
|
+
Do not allow using reserved names (`Anyway::Config` method names).
|
225
|
+
Allow only alphanumeric names (matching `/^[a-z_]([\w]+)?$/`).
|
194
226
|
|
195
227
|
- Add Loaders API. ([@palkan][])
|
196
228
|
|
197
|
-
|
198
|
-
|
229
|
+
All config sources have standardized via _loaders_ API. It's possible to define
|
230
|
+
custom loaders or change the sources order.
|
199
231
|
|
200
232
|
## 2.0.0.pre2 (2019-04-26)
|
201
233
|
|
@@ -205,73 +237,58 @@
|
|
205
237
|
|
206
238
|
- **BREAKING** Changed the way of providing explicit values. ([@palkan][])
|
207
239
|
|
208
|
-
|
209
|
-
|
210
|
-
|
240
|
+
```ruby
|
241
|
+
# BEFORE
|
242
|
+
Config.new(overrides: data)
|
211
243
|
|
212
|
-
|
213
|
-
|
214
|
-
|
244
|
+
# AFTER
|
245
|
+
Config.new(data)
|
246
|
+
```
|
215
247
|
|
216
248
|
- Add Railtie. ([@palkan][])
|
217
249
|
|
218
|
-
|
250
|
+
`Anyway::Railtie` provides `Anyway::Settings` access via `Rails.applicaiton.configuration.anyway_config`.
|
219
251
|
|
220
|
-
|
221
|
-
|
252
|
+
It also adds `app/configs` path to autoload paths (low-level, `ActiveSupport::Dependencies`) to
|
253
|
+
make it possible to use configs in the app configuration files.
|
222
254
|
|
223
255
|
- Add test helpers. ([@palkan][])
|
224
256
|
|
225
|
-
|
226
|
-
|
257
|
+
Added `with_env` helper to test code in the context of the specified
|
258
|
+
environment variables.
|
227
259
|
|
228
|
-
|
229
|
-
|
260
|
+
Included automatically in RSpec for examples with the `type: :config` meta
|
261
|
+
or with the `spec/configs` path.
|
230
262
|
|
231
263
|
- Add support for _local_ files. ([@palkan][])
|
232
264
|
|
233
|
-
|
234
|
-
- `<config_name>.local.yml`
|
235
|
-
- `config/credentials/local.yml.enc` (for Rails 6).
|
265
|
+
Now users can store their personal configurations in _local_ files:
|
236
266
|
|
237
|
-
|
238
|
-
|
239
|
-
|
267
|
+
- `<config_name>.local.yml`
|
268
|
+
- `config/credentials/local.yml.enc` (for Rails 6).
|
269
|
+
|
270
|
+
Local configs are meant for using in development and only loaded if
|
271
|
+
`Anyway::Settings.use_local_files` is `true` (which is true by default if
|
272
|
+
`RACK_ENV` or `RAILS_ENV` env variable is equal to `"development"`).
|
240
273
|
|
241
274
|
- Add Rails credentials support. ([@palkan][])
|
242
275
|
|
243
|
-
|
244
|
-
|
276
|
+
The data from credentials is loaded after the data from YAML config and secrets,
|
277
|
+
but before environmental variables (i.e. env variables are _stronger_)
|
245
278
|
|
246
279
|
- Update config name inference logic. ([@palkan][])
|
247
280
|
|
248
|
-
|
249
|
-
- the class name has a form of `<Module>::Config` (`SomeModule::Config => "some_module"`)
|
250
|
-
- the class name has a form of `<Something>Config` (`SomeConfig => "some"`)
|
251
|
-
|
252
|
-
- Fix config classes inheritance. ([@palkan][])
|
253
|
-
|
254
|
-
Previously, inheritance didn't work due to the lack of proper handling of class-level
|
255
|
-
configuration (naming, option parses settings, defaults).
|
256
|
-
|
257
|
-
Now it's possible to extend config classes without breaking the original classes functionality.
|
281
|
+
Config name is automatically inferred only if:
|
258
282
|
|
259
|
-
|
260
|
-
|
283
|
+
- the class name has a form of `<Module>::Config` (`SomeModule::Config => "some_module"`)
|
284
|
+
- the class name has a form of `<Something>Config` (`SomeConfig => "some"`)
|
261
285
|
|
262
|
-
|
263
|
-
class MyAppBaseConfig < Anyway::Config
|
264
|
-
config_name :my_app
|
265
|
-
end
|
266
|
-
|
267
|
-
class MyServiceConfig < MyAppBaseConfig
|
268
|
-
end
|
286
|
+
- Fix config classes inheritance. ([@palkan][])
|
269
287
|
|
270
|
-
|
271
|
-
|
288
|
+
Previously, inheritance didn't work due to the lack of proper handling of class-level
|
289
|
+
configuration (naming, option parses settings, defaults).
|
272
290
|
|
273
|
-
|
274
|
-
- option parse extension are not overriden, but added to the parent class extensions
|
291
|
+
Now it's possible to extend config classes without breaking the original classes functionality.
|
275
292
|
|
276
293
|
- **Require Ruby >= 2.5.0.**
|
277
294
|
|
@@ -291,26 +308,26 @@
|
|
291
308
|
|
292
309
|
- Add OptionParse integration ([@jastkand][])
|
293
310
|
|
294
|
-
|
311
|
+
See more [PR#18](https://github.com/palkan/anyway_config/pull/18).
|
295
312
|
|
296
313
|
- Use underscored config name as an env prefix. ([@palkan][])
|
297
314
|
|
298
|
-
|
315
|
+
For a config class:
|
299
316
|
|
300
|
-
|
301
|
-
|
302
|
-
|
303
|
-
|
317
|
+
```ruby
|
318
|
+
class MyApp < Anyway::Config
|
319
|
+
end
|
320
|
+
```
|
304
321
|
|
305
|
-
|
322
|
+
Before this change we use `MYAPP_` prefix, now it's `MY_APP_`.
|
306
323
|
|
307
|
-
|
324
|
+
You can specify the prefix explicitly:
|
308
325
|
|
309
|
-
|
310
|
-
|
311
|
-
|
312
|
-
|
313
|
-
|
326
|
+
```ruby
|
327
|
+
class MyApp < Anyway::Config
|
328
|
+
env_prefix "MYAPP_"
|
329
|
+
end
|
330
|
+
```
|
314
331
|
|
315
332
|
## 1.3.0 (2018-06-15)
|
316
333
|
|
@@ -326,18 +343,18 @@ Now works on JRuby 9.1+.
|
|
326
343
|
|
327
344
|
- Allow to pass raw hash with explicit values to `Config.new`. ([@dsalahutdinov][])
|
328
345
|
|
329
|
-
|
346
|
+
Example:
|
330
347
|
|
331
|
-
|
332
|
-
|
333
|
-
|
334
|
-
|
335
|
-
|
336
|
-
|
337
|
-
|
338
|
-
|
348
|
+
```ruby
|
349
|
+
Sniffer::Config.new(
|
350
|
+
overrides: {
|
351
|
+
enabled: true,
|
352
|
+
storage: {capacity: 500}
|
353
|
+
}
|
354
|
+
)
|
355
|
+
```
|
339
356
|
|
340
|
-
|
357
|
+
See more [PR#10](https://github.com/palkan/anyway_config/pull/10).
|
341
358
|
|
342
359
|
## 1.1.2 (2017-11-19)
|
343
360
|
|
@@ -351,7 +368,7 @@ Now works on JRuby 9.1+.
|
|
351
368
|
|
352
369
|
- Add `#to_h` method. ([@palkan][])
|
353
370
|
|
354
|
-
|
371
|
+
See [#4](https://github.com/palkan/anyway_config/issues/4).
|
355
372
|
|
356
373
|
- Make it possible to extend configuration parameters. ([@palkan][])
|
357
374
|
|
@@ -365,17 +382,18 @@ Now works on JRuby 9.1+.
|
|
365
382
|
|
366
383
|
- Drop `active_support` dependency. ([@palkan][])
|
367
384
|
|
368
|
-
|
385
|
+
Use custom refinements instead of requiring `active_support`.
|
369
386
|
|
370
|
-
|
387
|
+
No we're dependency-free!
|
371
388
|
|
372
389
|
## 0.1.0 (2015-01-20)
|
373
390
|
|
374
|
-
|
391
|
+
- Initial version.
|
375
392
|
|
376
393
|
[@palkan]: https://github.com/palkan
|
377
394
|
[@onemanstartup]: https://github.com/onemanstartup
|
378
395
|
[@dsalahutdinov]: https://github.com/dsalahutdinov
|
379
396
|
[@charlie-wasp]: https://github.com/charlie-wasp
|
380
397
|
[@jastkand]: https://github.com/jastkand
|
381
|
-
[@
|
398
|
+
[@envek]: https://github.com/Envek
|
399
|
+
[@progapandist]: https://github.com/progapandist
|