anyway_config 1.4.3 → 1.4.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: a97f6978750cef7720cc23ca182e8a6456655cb8ece18d1becdcd5e58262b7b9
4
- data.tar.gz: 5be2a8fc609273c759cef30b3eaf3c6d470716dc722ebd2a75a32b4209fe42a9
3
+ metadata.gz: af77cb70b9fea95ccb938643fcf462f04ef0087a1b3811de9e9f66e696f29ad5
4
+ data.tar.gz: 771eeb316a5a11d9bd8072dd7f506ddd5a02d36995ccf2facec3f40dcbc412ea
5
5
  SHA512:
6
- metadata.gz: 4e7c52fde9b0db72b7429748d0950286facbd82731e98375494dbd4dedec4efd448cc83bc30df8802a98e25c8bd230587ee2d8e09475aab8541410df1208672e
7
- data.tar.gz: 932f662e306d85328a9a9131dcb8daab211bb87ee2f1177b68cce1c3b8c315ab2bd4ac4cd2e148c992e02f3ac4bfa4a0c32600b345957f61178cdd9aaa3c3d79
6
+ metadata.gz: 87d5c17d6ec017474112df69685edcdfe9c7547ae7ad82b4338a4dd3493afeef50d6102fe87e7b0a5070aa6ad48f4872371515f32443a443bc324a67dcdfd918
7
+ data.tar.gz: 7c4cb678483573bb6a4db45ea5c78bbf1d077fcc7e5486fe4e420cae2c4de09224611d1925cdddebdc80ea767e140870b81bbcf39ce2be9515761846db70cc13
@@ -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`. You can override this setting
148
- through special environment variable – 'MYGEM_CONF' – containing the path to the YAML file.
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 as with Rails.
150
+ Environmental variables work the same way too.
151
151
 
152
152
 
153
153
  ### Config clear and reload
@@ -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!(Anyway.env.fetch(env_prefix))
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
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module Anyway # :nodoc:
4
- VERSION = "1.4.3"
4
+ VERSION = "1.4.4"
5
5
  end
@@ -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
@@ -0,0 +1,2 @@
1
+ test:
2
+ host: "custom.host"
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.3
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-04 00:00:00.000000000 Z
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