anyway_config 2.0.0.pre → 2.0.0.pre2
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/README.md +27 -21
- data/lib/anyway.rb +1 -30
- data/lib/anyway/config.rb +3 -8
- data/lib/anyway/rails/config.rb +2 -2
- data/lib/anyway/version.rb +1 -1
- data/lib/anyway_config.rb +30 -1
- metadata +9 -47
- data/lib/anyway/ext/jruby.rb +0 -96
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 540aa91321939a31eb3982143a12cc17621bdcb23c61d2d24686f999ae28a144
|
4
|
+
data.tar.gz: 3215663dd3722892f0635d13163dc02521f515ce31f5c310402893f304387b2d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: a629cdb9ba784714cff8df41814a6520745b9f1a6fdce272da2a56fd9d6635d46365767c4ce1289c93fdb0f3c5e4d9167b9b617830ff719c555a2a5a6e19f915
|
7
|
+
data.tar.gz: '009fd89edf49b814bde0fa2c7d846fa3f086fe606386c067bc447f4f8c990853a580257cb943e07692b57b49674912fd041f29cc9dbbb9eb652aaa3ee3857776'
|
data/README.md
CHANGED
@@ -1,5 +1,6 @@
|
|
1
1
|
[](http://cultofmartians.com)
|
2
|
-
[](https://rubygems.org/gems/anyway_config) [](https://rubygems.org/gems/anyway_config) [](https://github.com/palkan/anyway_config/actions)
|
3
|
+
[](https://github.com/palkan/anyway_config/actions)
|
3
4
|
|
4
5
|
# Anyway Config
|
5
6
|
|
@@ -24,7 +25,7 @@ Libraries using Anyway Config:
|
|
24
25
|
|
25
26
|
## Installation
|
26
27
|
|
27
|
-
|
28
|
+
Adding to a gem:
|
28
29
|
|
29
30
|
```ruby
|
30
31
|
# my-cool-gem.gemspec
|
@@ -35,18 +36,18 @@ Gem::Specification.new do |spec|
|
|
35
36
|
end
|
36
37
|
```
|
37
38
|
|
38
|
-
|
39
|
+
Or adding to your project:
|
39
40
|
|
40
41
|
```ruby
|
41
42
|
# Gemfile
|
42
43
|
gem "anyway_config", "2.0.0.pre"
|
43
44
|
```
|
44
45
|
|
45
|
-
|
46
|
+
## Supported Ruby versions
|
46
47
|
|
47
|
-
|
48
|
-
|
49
|
-
|
48
|
+
- Ruby (MRI) >= 2.5.0
|
49
|
+
|
50
|
+
- JRuby >= 9.2.7
|
50
51
|
|
51
52
|
## Usage
|
52
53
|
|
@@ -87,6 +88,7 @@ MyCoolGem.config.user #=> "root"
|
|
87
88
|
Anyway Config relies on the notion of _config name_ to populate data.
|
88
89
|
|
89
90
|
By default, Anyway Config uses the config class name to infer the config name using the following rules:
|
91
|
+
|
90
92
|
- if the class name has a form of `<Module>::Config` then use the module name (`SomeModule::Config => "somemodule"`)
|
91
93
|
- if the class name has a form of `<Something>Config` then use the class name prefix (`SomeConfig => "some"`)
|
92
94
|
|
@@ -105,7 +107,7 @@ end
|
|
105
107
|
|
106
108
|
#### Customize env variable names prefix
|
107
109
|
|
108
|
-
By default, Anyway Config uses
|
110
|
+
By default, Anyway Config uses upper-cased config name as a prefix for env variable names (e.g.
|
109
111
|
`config_name :my_app` will result to parsing `MY_APP_` prefix).
|
110
112
|
|
111
113
|
You can set env prefix explicitly:
|
@@ -143,7 +145,7 @@ You can also create configuration objects without pre-defined schema (just like
|
|
143
145
|
# load data from config/my_app.yml, secrets.my_app (if using Rails), ENV["MY_APP_*"]
|
144
146
|
# MY_APP_VALUE=42
|
145
147
|
config = Anyway::Config.for(:my_app)
|
146
|
-
config
|
148
|
+
config["value"] #=> 42
|
147
149
|
|
148
150
|
# you can specify the config file path or env prefix
|
149
151
|
config = Anyway::Config.for(:my_app, config_path: "my_config.yml", env_prefix: "MYAPP")
|
@@ -185,6 +187,8 @@ my_cool_gem:
|
|
185
187
|
host: secret.host
|
186
188
|
```
|
187
189
|
|
190
|
+
**NOTE:** You can backport Rails 6 per-environment credentials to Rails 5.2 app using [this patch](https://gist.github.com/palkan/e27e4885535ff25753aefce45378e0cb).
|
191
|
+
|
188
192
|
- `ENV['MYCOOLGEM_*']`.
|
189
193
|
|
190
194
|
#### `app/configs`
|
@@ -202,8 +206,8 @@ We have the following config to fetch the Heroku provided [metadata](https://dev
|
|
202
206
|
# This data is provided by Heroku Dyno Metadadata add-on.
|
203
207
|
class HerokuConfig < Anyway::Config
|
204
208
|
attr_config :app_id, :app_name,
|
205
|
-
|
206
|
-
|
209
|
+
:dyno_id, :release_version,
|
210
|
+
:slug_commit
|
207
211
|
|
208
212
|
def hostname
|
209
213
|
"#{app_name}.herokuapp.com"
|
@@ -219,7 +223,7 @@ config.action_mailer.default_url_options = {host: HerokuConfig.new.hostname}
|
|
219
223
|
|
220
224
|
### Using with Ruby
|
221
225
|
|
222
|
-
When you're using Anyway Config in non-Rails environment, we're looking for a
|
226
|
+
When you're using Anyway Config in non-Rails environment, we're looking for a YAML config file
|
223
227
|
at `./config/<config-name>.yml`.
|
224
228
|
|
225
229
|
You can override this setting through special environment variable – 'MYCOOLGEM_CONF' – containing the path to the YAML file.
|
@@ -238,6 +242,7 @@ Environmental variables work the same way as with Rails.
|
|
238
242
|
It's useful to have personal, user-specific configuration in development, which extends the project-wide one.
|
239
243
|
|
240
244
|
We support this by looking at _local_ files when loading the configuration data:
|
245
|
+
|
241
246
|
- `<config_name>.local.yml` files (next to\* the _global_ `<config_name>.yml`)
|
242
247
|
- `config/credentials/local.yml.enc` (for Rails >= 6, generate it via `rails credentials:edit --environment local`).
|
243
248
|
|
@@ -246,7 +251,7 @@ config at this location, too.
|
|
246
251
|
|
247
252
|
Local configs are meant for using in development and only loaded if `Anyway::Settings.use_local_files` is `true` (which is true by default if `RACK_ENV` or `RAILS_ENV` env variable is equal to `"development"`).
|
248
253
|
|
249
|
-
**NOTE:** in Rails apps you can use `Rails.
|
254
|
+
**NOTE:** in Rails apps you can use `Rails.application.configuration.anyway_config.use_local_files`.
|
250
255
|
|
251
256
|
Don't forget to add `*.local.yml` (and `config/credentials/local.*`) to your `.gitignore`.
|
252
257
|
|
@@ -312,12 +317,12 @@ Rails 4.2 introduced new feature: `Rails.application.config_for`. It looks very
|
|
312
317
|
`Anyway::Config.for`, but there are some differences:
|
313
318
|
|
314
319
|
| Feature | Rails | Anyway Config |
|
315
|
-
| -------------
|
316
|
-
| load data from `config/app.yml` | yes
|
317
|
-
| load data from `secrets` | no | yes
|
318
|
-
| load data from `credentials` | no | yes
|
319
|
-
| load data from environment | no | yes
|
320
|
-
| local config files | no | yes
|
320
|
+
| ------------- |-------------:| -----:|
|
321
|
+
| load data from `config/app.yml` | yes | yes |
|
322
|
+
| load data from `secrets` | no | yes |
|
323
|
+
| load data from `credentials` | no | yes |
|
324
|
+
| load data from environment | no | yes |
|
325
|
+
| local config files | no | yes |
|
321
326
|
| return Hash with indifferent access | no | yes |
|
322
327
|
| support ERB within `config/app.yml` | yes | yes* |
|
323
328
|
| raise errors if file doesn't exist | yes | no |
|
@@ -328,11 +333,12 @@ But the main advantage of Anyway::Config is that it can be used [without Rails](
|
|
328
333
|
|
329
334
|
## How to set env vars
|
330
335
|
|
331
|
-
Environmental variables for your config should start with your config name,
|
336
|
+
Environmental variables for your config should start with your config name, upper-cased.
|
332
337
|
|
333
338
|
For example, if your config name is "mycoolgem" then the env var "MYCOOLGEM_PASSWORD" is used as `config.password`.
|
334
339
|
|
335
340
|
Environment variables are automatically serialized:
|
341
|
+
|
336
342
|
- `"True"`, `"t"` and `"yes"` to `true`;
|
337
343
|
- `"False"`, `"f"` and `"no"` to `false`;
|
338
344
|
- `"nil"` and `"null"` to `nil` (do you really need it?);
|
@@ -394,7 +400,7 @@ You can add it manually by requiring `"anyway/testing/helpers"` and including th
|
|
394
400
|
|
395
401
|
## Contributing
|
396
402
|
|
397
|
-
Bug reports and pull requests are welcome on GitHub at https://github.com/palkan/anyway_config.
|
403
|
+
Bug reports and pull requests are welcome on GitHub at [https://github.com/palkan/anyway_config](https://github.com/palkan/anyway_config).
|
398
404
|
|
399
405
|
## License
|
400
406
|
|
data/lib/anyway.rb
CHANGED
@@ -1,32 +1,3 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
4
|
-
require "anyway/version"
|
5
|
-
|
6
|
-
require "anyway/config"
|
7
|
-
require "anyway/rails/config" if defined?(::Rails::VERSION)
|
8
|
-
require "anyway/env"
|
9
|
-
|
10
|
-
# Use Settings name to not confuse with Config.
|
11
|
-
#
|
12
|
-
# Settings contain the library-wide configuration.
|
13
|
-
class Settings
|
14
|
-
class << self
|
15
|
-
# Define whether to load data from
|
16
|
-
# *.yml.local (or credentials/local.yml.enc)
|
17
|
-
attr_accessor :use_local_files
|
18
|
-
end
|
19
|
-
|
20
|
-
# By default, use local files only in development (that's the purpose if the local files)
|
21
|
-
self.use_local_files = (ENV["RACK_ENV"] == "development" || ENV["RAILS_ENV"] == "development")
|
22
|
-
end
|
23
|
-
|
24
|
-
class << self
|
25
|
-
def env
|
26
|
-
@env ||= ::Anyway::Env.new
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
require "anyway/railtie" if defined?(::Rails::VERSION)
|
31
|
-
require "anyway/testing" if ENV["RACK_ENV"] == "test" || ENV["RAILS_ENV"] == "test"
|
32
|
-
end
|
3
|
+
require "anyway_config"
|
data/lib/anyway/config.rb
CHANGED
@@ -3,20 +3,15 @@
|
|
3
3
|
require "anyway/optparse_config"
|
4
4
|
require "anyway/dynamic_config"
|
5
5
|
|
6
|
-
require "anyway/ext/jruby" if defined? JRUBY_VERSION
|
7
6
|
require "anyway/ext/deep_dup"
|
8
7
|
require "anyway/ext/deep_freeze"
|
9
8
|
require "anyway/ext/hash"
|
10
9
|
require "anyway/ext/string_serialize"
|
11
10
|
|
12
11
|
module Anyway # :nodoc:
|
13
|
-
|
14
|
-
|
15
|
-
|
16
|
-
using Anyway::Ext::DeepDup
|
17
|
-
using Anyway::Ext::DeepFreeze
|
18
|
-
using Anyway::Ext::Hash
|
19
|
-
end
|
12
|
+
using Anyway::Ext::DeepDup
|
13
|
+
using Anyway::Ext::DeepFreeze
|
14
|
+
using Anyway::Ext::Hash
|
20
15
|
using Anyway::Ext::StringSerialize
|
21
16
|
|
22
17
|
# Base config class
|
data/lib/anyway/rails/config.rb
CHANGED
@@ -62,7 +62,7 @@ module Anyway
|
|
62
62
|
|
63
63
|
creds_config.deep_merge!(::Rails.application.credentials.public_send(name) || {})
|
64
64
|
|
65
|
-
creds_config.deep_merge!(load_from_local_credentials(name: name)) if Anyway::Settings.use_local_files
|
65
|
+
creds_config.deep_merge!(load_from_local_credentials(name: name) || {}) if Anyway::Settings.use_local_files
|
66
66
|
creds_config
|
67
67
|
end
|
68
68
|
|
@@ -76,7 +76,7 @@ module Anyway
|
|
76
76
|
key_path: ::Rails.root.join("config/credentials/local.key")
|
77
77
|
)
|
78
78
|
|
79
|
-
creds.public_send(name)
|
79
|
+
creds.public_send(name)
|
80
80
|
end
|
81
81
|
|
82
82
|
def default_config_path(name)
|
data/lib/anyway/version.rb
CHANGED
data/lib/anyway_config.rb
CHANGED
@@ -1,3 +1,32 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
|
3
|
+
module Anyway # :nodoc:
|
4
|
+
require "anyway/version"
|
5
|
+
|
6
|
+
require "anyway/config"
|
7
|
+
require "anyway/rails/config" if defined?(::Rails::VERSION)
|
8
|
+
require "anyway/env"
|
9
|
+
|
10
|
+
# Use Settings name to not confuse with Config.
|
11
|
+
#
|
12
|
+
# Settings contain the library-wide configuration.
|
13
|
+
class Settings
|
14
|
+
class << self
|
15
|
+
# Define whether to load data from
|
16
|
+
# *.yml.local (or credentials/local.yml.enc)
|
17
|
+
attr_accessor :use_local_files
|
18
|
+
end
|
19
|
+
|
20
|
+
# By default, use local files only in development (that's the purpose if the local files)
|
21
|
+
self.use_local_files = (ENV["RACK_ENV"] == "development" || ENV["RAILS_ENV"] == "development")
|
22
|
+
end
|
23
|
+
|
24
|
+
class << self
|
25
|
+
def env
|
26
|
+
@env ||= ::Anyway::Env.new
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
require "anyway/railtie" if defined?(::Rails::VERSION)
|
31
|
+
require "anyway/testing" if ENV["RACK_ENV"] == "test" || ENV["RAILS_ENV"] == "test"
|
32
|
+
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: anyway_config
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.0.0.
|
4
|
+
version: 2.0.0.pre2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Vladimir Dementyev
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-04
|
11
|
+
date: 2019-10-04 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -38,34 +38,6 @@ dependencies:
|
|
38
38
|
- - "~>"
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '3.8'
|
41
|
-
- !ruby/object:Gem::Dependency
|
42
|
-
name: rubocop
|
43
|
-
requirement: !ruby/object:Gem::Requirement
|
44
|
-
requirements:
|
45
|
-
- - "~>"
|
46
|
-
- !ruby/object:Gem::Version
|
47
|
-
version: 0.63.0
|
48
|
-
type: :development
|
49
|
-
prerelease: false
|
50
|
-
version_requirements: !ruby/object:Gem::Requirement
|
51
|
-
requirements:
|
52
|
-
- - "~>"
|
53
|
-
- !ruby/object:Gem::Version
|
54
|
-
version: 0.63.0
|
55
|
-
- !ruby/object:Gem::Dependency
|
56
|
-
name: rubocop-md
|
57
|
-
requirement: !ruby/object:Gem::Requirement
|
58
|
-
requirements:
|
59
|
-
- - "~>"
|
60
|
-
- !ruby/object:Gem::Version
|
61
|
-
version: '0.2'
|
62
|
-
type: :development
|
63
|
-
prerelease: false
|
64
|
-
version_requirements: !ruby/object:Gem::Requirement
|
65
|
-
requirements:
|
66
|
-
- - "~>"
|
67
|
-
- !ruby/object:Gem::Version
|
68
|
-
version: '0.2'
|
69
41
|
- !ruby/object:Gem::Dependency
|
70
42
|
name: simplecov
|
71
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,20 +52,6 @@ dependencies:
|
|
80
52
|
- - ">="
|
81
53
|
- !ruby/object:Gem::Version
|
82
54
|
version: 0.3.8
|
83
|
-
- !ruby/object:Gem::Dependency
|
84
|
-
name: standard
|
85
|
-
requirement: !ruby/object:Gem::Requirement
|
86
|
-
requirements:
|
87
|
-
- - "~>"
|
88
|
-
- !ruby/object:Gem::Version
|
89
|
-
version: 0.0.12
|
90
|
-
type: :development
|
91
|
-
prerelease: false
|
92
|
-
version_requirements: !ruby/object:Gem::Requirement
|
93
|
-
requirements:
|
94
|
-
- - "~>"
|
95
|
-
- !ruby/object:Gem::Version
|
96
|
-
version: 0.0.12
|
97
55
|
description: "\n Configuration DSL for Ruby libraries and applications.\n Allows
|
98
56
|
you to easily follow the twelve-factor application principles (https://12factor.net/config).\n
|
99
57
|
\ "
|
@@ -112,7 +70,6 @@ files:
|
|
112
70
|
- lib/anyway/ext/deep_dup.rb
|
113
71
|
- lib/anyway/ext/deep_freeze.rb
|
114
72
|
- lib/anyway/ext/hash.rb
|
115
|
-
- lib/anyway/ext/jruby.rb
|
116
73
|
- lib/anyway/ext/string_serialize.rb
|
117
74
|
- lib/anyway/loaders/env_loader.rb
|
118
75
|
- lib/anyway/loaders/secrets_loader.rb
|
@@ -128,7 +85,12 @@ files:
|
|
128
85
|
homepage: http://github.com/palkan/anyway_config
|
129
86
|
licenses:
|
130
87
|
- MIT
|
131
|
-
metadata:
|
88
|
+
metadata:
|
89
|
+
bug_tracker_uri: http://github.com/palkan/anyway_config/issues
|
90
|
+
changelog_uri: https://github.com/palkan/anyway_config/blob/master/CHANGELOG.md
|
91
|
+
documentation_uri: http://github.com/palkan/anyway_config
|
92
|
+
homepage_uri: http://github.com/palkan/anyway_config
|
93
|
+
source_code_uri: http://github.com/palkan/anyway_config
|
132
94
|
post_install_message:
|
133
95
|
rdoc_options: []
|
134
96
|
require_paths:
|
@@ -144,7 +106,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
144
106
|
- !ruby/object:Gem::Version
|
145
107
|
version: 1.3.1
|
146
108
|
requirements: []
|
147
|
-
rubygems_version: 3.0.
|
109
|
+
rubygems_version: 3.0.4
|
148
110
|
signing_key:
|
149
111
|
specification_version: 4
|
150
112
|
summary: Configuration DSL for Ruby libraries and applications
|
data/lib/anyway/ext/jruby.rb
DELETED
@@ -1,96 +0,0 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
|
-
module Anyway
|
4
|
-
module Ext
|
5
|
-
# JRuby 9.2.5.0. has a regression which breaks multiple refinements for the same
|
6
|
-
# class, so we put them in one God-refinement
|
7
|
-
# See https://github.com/jruby/jruby/issues/5550
|
8
|
-
#
|
9
|
-
# Should be fixed in 9.2.6.0
|
10
|
-
module JRuby
|
11
|
-
refine ::Hash do
|
12
|
-
# Based on ActiveSupport http://api.rubyonrails.org/classes/Hash.html#method-i-deep_dup
|
13
|
-
def deep_dup
|
14
|
-
each_with_object(dup) do |(key, value), hash|
|
15
|
-
hash[key] = if value.is_a?(::Hash) || value.is_a?(::Array)
|
16
|
-
value.deep_dup
|
17
|
-
else
|
18
|
-
value
|
19
|
-
end
|
20
|
-
end
|
21
|
-
end
|
22
|
-
|
23
|
-
def deep_freeze
|
24
|
-
freeze
|
25
|
-
each_value do |value|
|
26
|
-
value.deep_freeze if value.is_a?(::Hash) || value.is_a?(::Array)
|
27
|
-
end
|
28
|
-
end
|
29
|
-
|
30
|
-
# From ActiveSupport http://api.rubyonrails.org/classes/Hash.html#method-i-deep_merge
|
31
|
-
def deep_merge!(other_hash)
|
32
|
-
other_hash.each_pair do |current_key, other_value|
|
33
|
-
this_value = self[current_key]
|
34
|
-
|
35
|
-
if this_value.is_a?(::Hash) && other_value.is_a?(::Hash)
|
36
|
-
this_value.deep_merge!(other_value)
|
37
|
-
this_value
|
38
|
-
else
|
39
|
-
self[current_key] = other_value
|
40
|
-
end
|
41
|
-
end
|
42
|
-
|
43
|
-
self
|
44
|
-
end
|
45
|
-
|
46
|
-
def stringify_keys!
|
47
|
-
keys.each do |key|
|
48
|
-
value = delete(key)
|
49
|
-
value.stringify_keys! if value.is_a?(::Hash)
|
50
|
-
self[key.to_s] = value
|
51
|
-
end
|
52
|
-
|
53
|
-
self
|
54
|
-
end
|
55
|
-
end
|
56
|
-
|
57
|
-
refine ::Array do
|
58
|
-
# From ActiveSupport http://api.rubyonrails.org/classes/Array.html#method-i-deep_dup
|
59
|
-
def deep_dup
|
60
|
-
map do |value|
|
61
|
-
if value.is_a?(::Hash) || value.is_a?(::Array)
|
62
|
-
value.deep_dup
|
63
|
-
else
|
64
|
-
value
|
65
|
-
end
|
66
|
-
end
|
67
|
-
end
|
68
|
-
|
69
|
-
def deep_freeze
|
70
|
-
freeze
|
71
|
-
each do |value|
|
72
|
-
value.deep_freeze if value.is_a?(::Hash) || value.is_a?(::Array)
|
73
|
-
end
|
74
|
-
end
|
75
|
-
end
|
76
|
-
|
77
|
-
begin
|
78
|
-
require "active_support/core_ext/hash/indifferent_access"
|
79
|
-
rescue LoadError
|
80
|
-
end
|
81
|
-
|
82
|
-
if defined?(::ActiveSupport::HashWithIndifferentAccess)
|
83
|
-
refine ::ActiveSupport::HashWithIndifferentAccess do
|
84
|
-
def deep_freeze
|
85
|
-
freeze
|
86
|
-
each_value do |value|
|
87
|
-
value.deep_freeze if value.is_a?(::Hash) || value.is_a?(::Array)
|
88
|
-
end
|
89
|
-
end
|
90
|
-
end
|
91
|
-
end
|
92
|
-
|
93
|
-
using self
|
94
|
-
end
|
95
|
-
end
|
96
|
-
end
|