canfig 0.0.10 → 0.0.11
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/canfig/config.rb +1 -1
- data/lib/canfig/env_config.rb +11 -5
- data/lib/canfig/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: ba430bd04920933ac504636144cb797457e51446c1850c02ce8ba76a2fab1136
|
4
|
+
data.tar.gz: 9b38d00d36ab5928c606a5aa869cb26597276743d9433f558b079dd8487ce2ec
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: acf50db63b8d815cb835fc8ae8213e009040aecb68f17d1c09e760ef5fe10087af3eb5c9db91507385fc62617c1bc146b6bc4113addde3e803b5c5fd072c5414
|
7
|
+
data.tar.gz: d97d1a93681dfe5c13ef6ea893eb2817cf5a6484a18b77ef40b2ea2da99fd12b2f54823c441f78d2db848e017091f0600e42b61dd20fa80e701549032890edac
|
data/lib/canfig/config.rb
CHANGED
@@ -39,7 +39,7 @@ module Canfig
|
|
39
39
|
def env(key, default=nil, &block)
|
40
40
|
@state[key] ||= begin
|
41
41
|
val = ENV.fetch(key.to_s.underscore.upcase, default, &block)
|
42
|
-
val && ENV.key?(val) ? env(val, default, &block) : val
|
42
|
+
val && ENV.key?(val.to_s) ? env(val, default, &block) : val
|
43
43
|
end
|
44
44
|
end
|
45
45
|
|
data/lib/canfig/env_config.rb
CHANGED
@@ -2,9 +2,12 @@ module Canfig
|
|
2
2
|
class EnvConfig < OpenConfig
|
3
3
|
attr_reader :namespace
|
4
4
|
|
5
|
-
def initialize(namespace=nil, **
|
5
|
+
def initialize(namespace=nil, **attributes, &block)
|
6
6
|
@namespace = namespace ? "#{namespace.to_s.underscore.upcase.gsub(/_$/, '')}_" : namespace
|
7
|
-
super(
|
7
|
+
super(*attributes.keys, &block)
|
8
|
+
attributes.each do |key,val|
|
9
|
+
env(key, val)
|
10
|
+
end
|
8
11
|
end
|
9
12
|
|
10
13
|
def get(key, default=nil, &block)
|
@@ -12,9 +15,12 @@ module Canfig
|
|
12
15
|
end
|
13
16
|
|
14
17
|
def env(key, default=nil, &block)
|
15
|
-
key
|
16
|
-
|
17
|
-
|
18
|
+
@state[key.to_sym] ||= begin
|
19
|
+
key = key.to_s.underscore.upcase
|
20
|
+
key = key.gsub(/^#{namespace}/, '') if namespace
|
21
|
+
val = ENV.fetch("#{namespace}#{key}", default, &block)
|
22
|
+
val && ENV.key?(val.to_s) ? env(val, default, &block) : val
|
23
|
+
end
|
18
24
|
end
|
19
25
|
end
|
20
26
|
end
|
data/lib/canfig/version.rb
CHANGED