canfig 0.0.9 → 0.0.14
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 +8 -3
- data/lib/canfig/env_config.rb +22 -8
- data/lib/canfig/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f5cf1818dc05ca85705475f4f667a025716f351f6c846b17ad2ca8d71ca94967
|
4
|
+
data.tar.gz: 0b94d7c75bbb9e4cb443ee07094881af53b42dca689c5373fc28b04fb76f5fd9
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c07a4de23a58dffad06507b3dcadbae8c5ba77b24ab841a98ce1064c37b1caf55726502c9ca2d4abeab8ce753b7869b9aea52c316ce5309a972d15673ea973e3
|
7
|
+
data.tar.gz: 3e7ac47e76ece7eb4311fbca9b3786ba445a6ed59b4e520aaaf44350f567c5c420762f7770bd2dc78e9d8f5a43c614d154ed9a6c37bf3a56305a649cd881f4bb
|
data/lib/canfig/config.rb
CHANGED
@@ -37,8 +37,13 @@ module Canfig
|
|
37
37
|
end
|
38
38
|
|
39
39
|
def env(key, default=nil, &block)
|
40
|
-
|
41
|
-
|
40
|
+
@state[key] ||= begin
|
41
|
+
val = ENV.fetch(key.to_s.underscore.upcase, default, &block)
|
42
|
+
val = default if val.blank?
|
43
|
+
val = env(val, default, &block) if val && ENV.key?(val.to_s)
|
44
|
+
val = eval(val) if val == 'true' || val == 'false'
|
45
|
+
val
|
46
|
+
end
|
42
47
|
end
|
43
48
|
|
44
49
|
def clear(*keys)
|
@@ -53,7 +58,7 @@ module Canfig
|
|
53
58
|
|
54
59
|
def get(key, default=nil, &block)
|
55
60
|
raise NoMethodError, "undefined method `#{key.to_s}' for #{self.to_s}" unless allowed?(key)
|
56
|
-
@state[key]
|
61
|
+
@state[key] || (block_given? ? yield : default)
|
57
62
|
end
|
58
63
|
|
59
64
|
def [](key)
|
data/lib/canfig/env_config.rb
CHANGED
@@ -2,19 +2,33 @@ module Canfig
|
|
2
2
|
class EnvConfig < OpenConfig
|
3
3
|
attr_reader :namespace
|
4
4
|
|
5
|
-
def
|
6
|
-
|
7
|
-
|
5
|
+
def configure_with_args(argh)
|
6
|
+
save_state! do
|
7
|
+
argh.symbolize_keys.each { |key,val| env(key, val) }
|
8
|
+
end
|
8
9
|
end
|
9
10
|
|
10
|
-
def
|
11
|
-
|
11
|
+
def get(key, default=nil, &block)
|
12
|
+
super || env(key, default, &block)
|
12
13
|
end
|
13
14
|
|
14
15
|
def env(key, default=nil, &block)
|
15
|
-
key
|
16
|
-
|
17
|
-
|
16
|
+
@state[key.to_sym] ||= begin
|
17
|
+
key = key.to_s.underscore.upcase
|
18
|
+
key = key.gsub(/^#{namespace}/, '') if namespace
|
19
|
+
val = ENV.fetch("#{namespace}#{key}", default, &block)
|
20
|
+
val = default if val.blank?
|
21
|
+
val = env(val, default, &block) if val && ENV.key?(val.to_s)
|
22
|
+
val = eval(val) if val == 'true' || val == 'false'
|
23
|
+
val
|
24
|
+
end
|
25
|
+
end
|
26
|
+
|
27
|
+
protected
|
28
|
+
|
29
|
+
def initialize(namespace=nil, **attributes, &block)
|
30
|
+
@namespace = namespace ? "#{namespace.to_s.underscore.upcase.gsub(/_$/, '')}_" : namespace
|
31
|
+
super(**attributes, &block)
|
18
32
|
end
|
19
33
|
end
|
20
34
|
end
|
data/lib/canfig/version.rb
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: canfig
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.14
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Mark Rebec
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2021-01-01 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|