anyway_config 2.0.2 → 2.1.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 +4 -4
- data/CHANGELOG.md +215 -181
- data/README.md +70 -10
- 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 +46 -69
- 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 +18 -26
- data/lib/.rbnext/3.0/anyway/config.rb +391 -0
- data/lib/.rbnext/3.0/anyway/loaders.rb +77 -0
- data/lib/.rbnext/3.0/anyway/loaders/base.rb +21 -0
- data/lib/.rbnext/3.0/anyway/tracing.rb +183 -0
- data/lib/anyway/config.rb +46 -69
- 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.rb +1 -3
- data/lib/anyway/loaders/base.rb +2 -4
- data/lib/anyway/loaders/yaml.rb +4 -4
- 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/testing.rb +1 -1
- data/lib/anyway/tracing.rb +17 -27
- data/lib/anyway/utils/deep_merge.rb +21 -0
- data/lib/anyway/version.rb +1 -1
- data/lib/anyway_config.rb +3 -1
- metadata +20 -8
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,16 +1,64 @@
|
|
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
|
+
|
35
|
+
## 2.0.6 (2020-07-7)
|
36
|
+
|
37
|
+
- Fix Ruby 2.7 warnings. ([@palkan][])
|
38
|
+
|
39
|
+
## 2.0.5 (2020-05-15)
|
40
|
+
|
41
|
+
- Use `YAML.load` instead of `YAML.safe_laad`. ([@palkan][])
|
42
|
+
|
43
|
+
## 2.0.4 (2020-05-15)
|
44
|
+
|
45
|
+
- Fix regression with adding `ruby-next` as a runtime dependency even for RubyGems release. ([@palkan][])
|
46
|
+
|
47
|
+
## 2.0.3 (2020-05-12)
|
48
|
+
|
49
|
+
- Enable [auto-transpiling](https://github.com/ruby-next/ruby-next#transpiled-files-vs-vcs-vs-installing-from-source) to allow installing from source. ([@palkan][])
|
50
|
+
|
3
51
|
## 2.0.2 (2020-04-24)
|
4
52
|
|
5
53
|
- Make sure configs are eager loaded in Rails when `config.eager_load = true`. ([@palkan][])
|
6
54
|
|
7
|
-
|
55
|
+
Fixes [#58](https://github.com/palkan/anyway_config/issues/58).
|
8
56
|
|
9
57
|
## 2.0.1 (2020-04-15)
|
10
58
|
|
11
59
|
- Fix loading Railtie when application has been already initialized. ([@palkan][])
|
12
60
|
|
13
|
-
|
61
|
+
Fixes [#56](https://github.com/palkan/anyway_config/issues/56).
|
14
62
|
|
15
63
|
## 2.0.0 (2020-04-14)
|
16
64
|
|
@@ -20,166 +68,166 @@
|
|
20
68
|
|
21
69
|
- Add predicate methods for attributes with boolean defaults. ([@palkan][])
|
22
70
|
|
23
|
-
|
71
|
+
For example:
|
24
72
|
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
73
|
+
```ruby
|
74
|
+
class MyConfig < Anyway::Config
|
75
|
+
attr_config :key, :secret, debug: false
|
76
|
+
end
|
29
77
|
|
30
|
-
|
31
|
-
|
32
|
-
|
78
|
+
MyConfig.new.debug? #=> false
|
79
|
+
MyConfig.new(debug: true).debug? #=> true
|
80
|
+
```
|
33
81
|
|
34
82
|
- Add `Config#deconstruct_keys`. ([@palkan][])
|
35
83
|
|
36
|
-
|
84
|
+
Now you can use configs in pattern matching:
|
37
85
|
|
38
|
-
|
39
|
-
|
40
|
-
|
41
|
-
|
42
|
-
|
43
|
-
|
44
|
-
|
45
|
-
|
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
|
+
```
|
46
94
|
|
47
95
|
- Add pretty_print support. ([@palkan][])
|
48
96
|
|
49
|
-
|
50
|
-
|
97
|
+
Whenever you use `pp`, the output would contain pretty formatted config information
|
98
|
+
including the sources.
|
51
99
|
|
52
|
-
|
100
|
+
Example:
|
53
101
|
|
54
|
-
|
55
|
-
|
102
|
+
```ruby
|
103
|
+
pp CoolConfig.new
|
56
104
|
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
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
|
+
```
|
67
115
|
|
68
116
|
- Add source tracing support. ([@palkan][])
|
69
117
|
|
70
|
-
|
71
|
-
|
72
|
-
|
73
|
-
|
74
|
-
|
75
|
-
|
76
|
-
|
77
|
-
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
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
|
+
```
|
85
133
|
|
86
134
|
- Change the way Rails configs autoloading works. ([@palkan][])
|
87
135
|
|
88
|
-
|
89
|
-
|
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).
|
90
138
|
|
91
|
-
|
92
|
-
|
93
|
-
|
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.
|
94
142
|
|
95
|
-
|
96
|
-
|
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`:
|
97
145
|
|
98
|
-
|
99
|
-
|
100
|
-
|
146
|
+
```ruby
|
147
|
+
config.anyway_config.autoload_static_config_path = "app/configs"
|
148
|
+
```
|
101
149
|
|
102
|
-
|
150
|
+
You can do this by running the generator:
|
103
151
|
|
104
|
-
|
105
|
-
|
106
|
-
|
152
|
+
```sh
|
153
|
+
rails g anyway:install --configs-path=app/configs
|
154
|
+
```
|
107
155
|
|
108
156
|
- Add Rails generators. ([@palkan][])
|
109
157
|
|
110
|
-
|
158
|
+
You can create config classes with the predefined attributes like this:
|
111
159
|
|
112
|
-
|
113
|
-
|
114
|
-
|
160
|
+
```sh
|
161
|
+
rails generate config aws access_key_id secret_access_key region
|
162
|
+
```
|
115
163
|
|
116
164
|
- **BREAKING** The accessors generated by `attr_config` are not longer `attr_accessor`-s. ([@palkan][])
|
117
165
|
|
118
|
-
|
119
|
-
|
166
|
+
You cannot rely on instance variables anymore. Instead, you can use `super` when overriding accessors or
|
167
|
+
`values[name]`:
|
120
168
|
|
121
|
-
|
122
|
-
|
169
|
+
```ruby
|
170
|
+
attr_config :host, :port, :url, :meta
|
123
171
|
|
124
|
-
|
125
|
-
|
126
|
-
|
127
|
-
|
172
|
+
# override writer to handle type coercion
|
173
|
+
def meta=(val)
|
174
|
+
super JSON.parse(val)
|
175
|
+
end
|
128
176
|
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
177
|
+
# or override reader to handle missing values
|
178
|
+
def url
|
179
|
+
values[:url] ||= "#{host}:#{port}"
|
180
|
+
end
|
133
181
|
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
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
|
+
```
|
140
188
|
|
141
|
-
|
142
|
-
|
189
|
+
**NOTE**: we still set instance variables in writers (for backward compatibility), but that would
|
190
|
+
be removed in 2.1.
|
143
191
|
|
144
192
|
- Add `Config#dig` method. ([@palkan][])
|
145
193
|
|
146
194
|
- Add ability to specify types for OptionParser options. ([@palkan][])
|
147
195
|
|
148
|
-
|
149
|
-
|
150
|
-
|
151
|
-
|
152
|
-
|
153
|
-
|
154
|
-
|
155
|
-
|
196
|
+
```ruby
|
197
|
+
describe_options(
|
198
|
+
concurrency: {
|
199
|
+
desc: "number of threads to use",
|
200
|
+
type: String
|
201
|
+
}
|
202
|
+
)
|
203
|
+
```
|
156
204
|
|
157
205
|
- Add param presence validation. ([@palkan][])
|
158
206
|
|
159
|
-
|
160
|
-
|
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):
|
161
209
|
|
162
|
-
|
163
|
-
|
164
|
-
|
210
|
+
```ruby
|
211
|
+
class MyConfig < Anyway::Config
|
212
|
+
attr_config :api_key, :api_secret, :debug
|
165
213
|
|
166
|
-
|
167
|
-
|
214
|
+
required :api_key, :api_secret
|
215
|
+
end
|
168
216
|
|
169
|
-
|
170
|
-
|
217
|
+
MyConfig.new(api_secret: "") #=> raises Anyway::Config::ValidationError
|
218
|
+
```
|
171
219
|
|
172
|
-
|
220
|
+
You can change the validation behaviour by overriding the `#validate!` method in your config class.
|
173
221
|
|
174
222
|
- Validate config attribute names. ([@palkan][])
|
175
223
|
|
176
|
-
|
177
|
-
|
224
|
+
Do not allow using reserved names (`Anyway::Config` method names).
|
225
|
+
Allow only alphanumeric names (matching `/^[a-z_]([\w]+)?$/`).
|
178
226
|
|
179
227
|
- Add Loaders API. ([@palkan][])
|
180
228
|
|
181
|
-
|
182
|
-
|
229
|
+
All config sources have standardized via _loaders_ API. It's possible to define
|
230
|
+
custom loaders or change the sources order.
|
183
231
|
|
184
232
|
## 2.0.0.pre2 (2019-04-26)
|
185
233
|
|
@@ -189,73 +237,58 @@
|
|
189
237
|
|
190
238
|
- **BREAKING** Changed the way of providing explicit values. ([@palkan][])
|
191
239
|
|
192
|
-
|
193
|
-
|
194
|
-
|
240
|
+
```ruby
|
241
|
+
# BEFORE
|
242
|
+
Config.new(overrides: data)
|
195
243
|
|
196
|
-
|
197
|
-
|
198
|
-
|
244
|
+
# AFTER
|
245
|
+
Config.new(data)
|
246
|
+
```
|
199
247
|
|
200
248
|
- Add Railtie. ([@palkan][])
|
201
249
|
|
202
|
-
|
250
|
+
`Anyway::Railtie` provides `Anyway::Settings` access via `Rails.applicaiton.configuration.anyway_config`.
|
203
251
|
|
204
|
-
|
205
|
-
|
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.
|
206
254
|
|
207
255
|
- Add test helpers. ([@palkan][])
|
208
256
|
|
209
|
-
|
210
|
-
|
257
|
+
Added `with_env` helper to test code in the context of the specified
|
258
|
+
environment variables.
|
211
259
|
|
212
|
-
|
213
|
-
|
260
|
+
Included automatically in RSpec for examples with the `type: :config` meta
|
261
|
+
or with the `spec/configs` path.
|
214
262
|
|
215
263
|
- Add support for _local_ files. ([@palkan][])
|
216
264
|
|
217
|
-
|
218
|
-
- `<config_name>.local.yml`
|
219
|
-
- `config/credentials/local.yml.enc` (for Rails 6).
|
265
|
+
Now users can store their personal configurations in _local_ files:
|
220
266
|
|
221
|
-
|
222
|
-
|
223
|
-
|
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"`).
|
224
273
|
|
225
274
|
- Add Rails credentials support. ([@palkan][])
|
226
275
|
|
227
|
-
|
228
|
-
|
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_)
|
229
278
|
|
230
279
|
- Update config name inference logic. ([@palkan][])
|
231
280
|
|
232
|
-
|
233
|
-
- the class name has a form of `<Module>::Config` (`SomeModule::Config => "some_module"`)
|
234
|
-
- the class name has a form of `<Something>Config` (`SomeConfig => "some"`)
|
235
|
-
|
236
|
-
- Fix config classes inheritance. ([@palkan][])
|
237
|
-
|
238
|
-
Previously, inheritance didn't work due to the lack of proper handling of class-level
|
239
|
-
configuration (naming, option parses settings, defaults).
|
281
|
+
Config name is automatically inferred only if:
|
240
282
|
|
241
|
-
|
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"`)
|
242
285
|
|
243
|
-
|
244
|
-
- if `config_name` is explicitly defined on class, it's inherited by subclasses:
|
245
|
-
|
246
|
-
```ruby
|
247
|
-
class MyAppBaseConfig < Anyway::Config
|
248
|
-
config_name :my_app
|
249
|
-
end
|
250
|
-
|
251
|
-
class MyServiceConfig < MyAppBaseConfig
|
252
|
-
end
|
286
|
+
- Fix config classes inheritance. ([@palkan][])
|
253
287
|
|
254
|
-
|
255
|
-
|
288
|
+
Previously, inheritance didn't work due to the lack of proper handling of class-level
|
289
|
+
configuration (naming, option parses settings, defaults).
|
256
290
|
|
257
|
-
|
258
|
-
- 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.
|
259
292
|
|
260
293
|
- **Require Ruby >= 2.5.0.**
|
261
294
|
|
@@ -275,26 +308,26 @@
|
|
275
308
|
|
276
309
|
- Add OptionParse integration ([@jastkand][])
|
277
310
|
|
278
|
-
|
311
|
+
See more [PR#18](https://github.com/palkan/anyway_config/pull/18).
|
279
312
|
|
280
313
|
- Use underscored config name as an env prefix. ([@palkan][])
|
281
314
|
|
282
|
-
|
315
|
+
For a config class:
|
283
316
|
|
284
|
-
|
285
|
-
|
286
|
-
|
287
|
-
|
317
|
+
```ruby
|
318
|
+
class MyApp < Anyway::Config
|
319
|
+
end
|
320
|
+
```
|
288
321
|
|
289
|
-
|
322
|
+
Before this change we use `MYAPP_` prefix, now it's `MY_APP_`.
|
290
323
|
|
291
|
-
|
324
|
+
You can specify the prefix explicitly:
|
292
325
|
|
293
|
-
|
294
|
-
|
295
|
-
|
296
|
-
|
297
|
-
|
326
|
+
```ruby
|
327
|
+
class MyApp < Anyway::Config
|
328
|
+
env_prefix "MYAPP_"
|
329
|
+
end
|
330
|
+
```
|
298
331
|
|
299
332
|
## 1.3.0 (2018-06-15)
|
300
333
|
|
@@ -310,18 +343,18 @@ Now works on JRuby 9.1+.
|
|
310
343
|
|
311
344
|
- Allow to pass raw hash with explicit values to `Config.new`. ([@dsalahutdinov][])
|
312
345
|
|
313
|
-
|
346
|
+
Example:
|
314
347
|
|
315
|
-
|
316
|
-
|
317
|
-
|
318
|
-
|
319
|
-
|
320
|
-
|
321
|
-
|
322
|
-
|
348
|
+
```ruby
|
349
|
+
Sniffer::Config.new(
|
350
|
+
overrides: {
|
351
|
+
enabled: true,
|
352
|
+
storage: {capacity: 500}
|
353
|
+
}
|
354
|
+
)
|
355
|
+
```
|
323
356
|
|
324
|
-
|
357
|
+
See more [PR#10](https://github.com/palkan/anyway_config/pull/10).
|
325
358
|
|
326
359
|
## 1.1.2 (2017-11-19)
|
327
360
|
|
@@ -335,7 +368,7 @@ Now works on JRuby 9.1+.
|
|
335
368
|
|
336
369
|
- Add `#to_h` method. ([@palkan][])
|
337
370
|
|
338
|
-
|
371
|
+
See [#4](https://github.com/palkan/anyway_config/issues/4).
|
339
372
|
|
340
373
|
- Make it possible to extend configuration parameters. ([@palkan][])
|
341
374
|
|
@@ -349,17 +382,18 @@ Now works on JRuby 9.1+.
|
|
349
382
|
|
350
383
|
- Drop `active_support` dependency. ([@palkan][])
|
351
384
|
|
352
|
-
|
385
|
+
Use custom refinements instead of requiring `active_support`.
|
353
386
|
|
354
|
-
|
387
|
+
No we're dependency-free!
|
355
388
|
|
356
389
|
## 0.1.0 (2015-01-20)
|
357
390
|
|
358
|
-
|
391
|
+
- Initial version.
|
359
392
|
|
360
393
|
[@palkan]: https://github.com/palkan
|
361
394
|
[@onemanstartup]: https://github.com/onemanstartup
|
362
395
|
[@dsalahutdinov]: https://github.com/dsalahutdinov
|
363
396
|
[@charlie-wasp]: https://github.com/charlie-wasp
|
364
397
|
[@jastkand]: https://github.com/jastkand
|
365
|
-
[@
|
398
|
+
[@envek]: https://github.com/Envek
|
399
|
+
[@progapandist]: https://github.com/progapandist
|