anyway_config 1.4.3 → 1.4.4
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 +5 -0
- data/README.md +5 -5
- data/lib/anyway/config.rb +13 -3
- data/lib/anyway/rails/config.rb +6 -1
- data/lib/anyway/version.rb +1 -1
- data/spec/config_spec.rb +7 -0
- data/spec/dummy/config/cool_custom.yml +2 -0
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: af77cb70b9fea95ccb938643fcf462f04ef0087a1b3811de9e9f66e696f29ad5
|
4
|
+
data.tar.gz: 771eeb316a5a11d9bd8072dd7f506ddd5a02d36995ccf2facec3f40dcbc412ea
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 87d5c17d6ec017474112df69685edcdfe9c7547ae7ad82b4338a4dd3493afeef50d6102fe87e7b0a5070aa6ad48f4872371515f32443a443bc324a67dcdfd918
|
7
|
+
data.tar.gz: 7c4cb678483573bb6a4db45ea5c78bbf1d077fcc7e5486fe4e420cae2c4de09224611d1925cdddebdc80ea767e140870b81bbcf39ce2be9515761846db70cc13
|
data/CHANGELOG.md
CHANGED
@@ -2,6 +2,10 @@
|
|
2
2
|
|
3
3
|
## master
|
4
4
|
|
5
|
+
## 1.4.4 (2019-02-07)
|
6
|
+
|
7
|
+
- Allow overriding default config file path via ENV with Rails integration ([@sponomarev][])
|
8
|
+
|
5
9
|
## 1.4.3 (2019-02-04)
|
6
10
|
|
7
11
|
- Add a temporary fix for JRuby regression [#5550](https://github.com/jruby/jruby/issues/5550). ([@palkan][])
|
@@ -105,3 +109,4 @@ Initial version.
|
|
105
109
|
[@dsalahutdinov]: https://github.com/dsalahutdinov
|
106
110
|
[@charlie-wasp]: https://github.com/charlie-wasp
|
107
111
|
[@jastkand]: https://github.com/jastkand
|
112
|
+
[@sponomarev]: https://github.com/sponomarev
|
data/README.md
CHANGED
@@ -99,7 +99,6 @@ explicitly, and it will be used as is:
|
|
99
99
|
```ruby
|
100
100
|
module MyCoolGem
|
101
101
|
class Config < Anyway::Config
|
102
|
-
config_name :cool_gem
|
103
102
|
env_prefix :really_cool # now variables, starting wih `REALLY_COOL_`, will be parsed
|
104
103
|
attr_config user: 'root', password: 'root', host: 'localhost', options: {}
|
105
104
|
end
|
@@ -136,7 +135,8 @@ config = Anyway::Config.for(:my_app)
|
|
136
135
|
|
137
136
|
Your config will be filled up with values from the following sources (ordered by priority from low to high):
|
138
137
|
|
139
|
-
- `RAILS_ROOT/config/my_cool_gem.yml` (for the current `RAILS_ENV`, supports `ERB`)
|
138
|
+
- `RAILS_ROOT/config/my_cool_gem.yml` (for the current `RAILS_ENV`, supports `ERB`). You can override this setting
|
139
|
+
through special environment variable – 'MYCOOLGEM_CONF' – containing the path to the YAML file.
|
140
140
|
|
141
141
|
- `Rails.application.secrets.my_cool_gem`
|
142
142
|
|
@@ -144,10 +144,10 @@ Your config will be filled up with values from the following sources (ordered by
|
|
144
144
|
|
145
145
|
### Using with Ruby
|
146
146
|
|
147
|
-
By default, Anyway Config is looking for a config YAML at `./config/<config-name>.yml
|
148
|
-
|
147
|
+
By default, Anyway Config is looking for a config YAML at `./config/<config-name>.yml` e.g. `./config/my_cool_gem.yml`.
|
148
|
+
You can override this location the same way as for Rails.
|
149
149
|
|
150
|
-
Environmental variables work the same way
|
150
|
+
Environmental variables work the same way too.
|
151
151
|
|
152
152
|
|
153
153
|
### Config clear and reload
|
data/lib/anyway/config.rb
CHANGED
@@ -156,14 +156,12 @@ module Anyway # :nodoc:
|
|
156
156
|
end
|
157
157
|
|
158
158
|
def load_from_file(config)
|
159
|
-
config_path = Anyway.env.fetch(env_prefix).delete('conf') ||
|
160
|
-
"./config/#{config_name}.yml"
|
161
159
|
config.deep_merge!(parse_yml(config_path) || {}) if config_path && File.file?(config_path)
|
162
160
|
config
|
163
161
|
end
|
164
162
|
|
165
163
|
def load_from_env(config)
|
166
|
-
config.deep_merge!(
|
164
|
+
config.deep_merge!(env_part)
|
167
165
|
config
|
168
166
|
end
|
169
167
|
|
@@ -188,6 +186,18 @@ module Anyway # :nodoc:
|
|
188
186
|
|
189
187
|
private
|
190
188
|
|
189
|
+
def env_part
|
190
|
+
Anyway.env.fetch(env_prefix)
|
191
|
+
end
|
192
|
+
|
193
|
+
def config_path
|
194
|
+
env_part.delete('conf') || default_config_path
|
195
|
+
end
|
196
|
+
|
197
|
+
def default_config_path
|
198
|
+
"./config/#{config_name}.yml"
|
199
|
+
end
|
200
|
+
|
191
201
|
def set_value(key, val)
|
192
202
|
send("#{key}=", val) if respond_to?(key)
|
193
203
|
end
|
data/lib/anyway/rails/config.rb
CHANGED
@@ -18,7 +18,6 @@ module Anyway
|
|
18
18
|
end
|
19
19
|
|
20
20
|
def load_from_file(config)
|
21
|
-
config_path = Rails.root.join("config", "#{@config_name}.yml")
|
22
21
|
config.deep_merge!(parse_yml(config_path)[Rails.env] || {}) if File.file? config_path
|
23
22
|
config
|
24
23
|
end
|
@@ -29,5 +28,11 @@ module Anyway
|
|
29
28
|
end
|
30
29
|
config
|
31
30
|
end
|
31
|
+
|
32
|
+
private
|
33
|
+
|
34
|
+
def default_config_path
|
35
|
+
Rails.root.join("config", "#{config_name}.yml")
|
36
|
+
end
|
32
37
|
end
|
33
38
|
end
|
data/lib/anyway/version.rb
CHANGED
data/spec/config_spec.rb
CHANGED
@@ -69,6 +69,13 @@ describe Anyway::Config do
|
|
69
69
|
expect(conf.user[:password]).to eq "root"
|
70
70
|
end
|
71
71
|
end
|
72
|
+
|
73
|
+
context "with overiden path" do
|
74
|
+
it "reads custom config path" do
|
75
|
+
ENV['COOL_CONF'] = Rails.root.join("config", "cool_custom.yml").to_s
|
76
|
+
expect(conf.host).to eq "custom.host"
|
77
|
+
end
|
78
|
+
end
|
72
79
|
end
|
73
80
|
|
74
81
|
describe "load from env" do
|
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: 1.4.
|
4
|
+
version: 1.4.4
|
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-02-
|
11
|
+
date: 2019-02-07 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -109,6 +109,7 @@ files:
|
|
109
109
|
- spec/dummy/config/application.rb
|
110
110
|
- spec/dummy/config/boot.rb
|
111
111
|
- spec/dummy/config/cool.yml
|
112
|
+
- spec/dummy/config/cool_custom.yml
|
112
113
|
- spec/dummy/config/database.yml
|
113
114
|
- spec/dummy/config/environment.rb
|
114
115
|
- spec/dummy/config/environments/test.rb
|