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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: cb0af652bc6aced0a5a7be703c93267bbef555c28f821c565c9c5b14f93b6d20
4
- data.tar.gz: cb3541d3ca774f5f7a331f75238ecef6231b62be3776b50ae52cac3b12182c6b
3
+ metadata.gz: f5cf1818dc05ca85705475f4f667a025716f351f6c846b17ad2ca8d71ca94967
4
+ data.tar.gz: 0b94d7c75bbb9e4cb443ee07094881af53b42dca689c5373fc28b04fb76f5fd9
5
5
  SHA512:
6
- metadata.gz: aab3a3c345efea85b20c75e8aec11ccd62baab19e8dcfa5b5870406a2731e6894311a21273b10cfea3476f037185b300e862e027a19bf8314fbb9300054d2b78
7
- data.tar.gz: ebc54005799b649dbecc527bd30f6bbad0149ad4fc022b2998323b0fe6b7888df12ffc1050a9884caee2ee14e30093f315408ed08e657b4e3a8dc657e3449459
6
+ metadata.gz: c07a4de23a58dffad06507b3dcadbae8c5ba77b24ab841a98ce1064c37b1caf55726502c9ca2d4abeab8ce753b7869b9aea52c316ce5309a972d15673ea973e3
7
+ data.tar.gz: 3e7ac47e76ece7eb4311fbca9b3786ba445a6ed59b4e520aaaf44350f567c5c420762f7770bd2dc78e9d8f5a43c614d154ed9a6c37bf3a56305a649cd881f4bb
@@ -37,8 +37,13 @@ module Canfig
37
37
  end
38
38
 
39
39
  def env(key, default=nil, &block)
40
- val = ENV.fetch(key.to_s.underscore.upcase, default, &block)
41
- val && ENV.key?(val) ? env(val, default, &block) : val
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] ||= env(key, default, &block)
61
+ @state[key] || (block_given? ? yield : default)
57
62
  end
58
63
 
59
64
  def [](key)
@@ -2,19 +2,33 @@ module Canfig
2
2
  class EnvConfig < OpenConfig
3
3
  attr_reader :namespace
4
4
 
5
- def initialize(namespace=nil, **options, &block)
6
- @namespace = namespace ? "#{namespace.to_s.underscore.upcase.gsub(/_$/, '')}_" : namespace
7
- super(**options, &block)
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 set(key, val)
11
- raise NotImplementedError, "You cannot set values on a Canfig::EnvConfig"
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 = key.to_s.underscore.upcase
16
- key = key.gsub(/^#{namespace}/, '') if namespace
17
- super("#{namespace}#{key}", default, &block)
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
@@ -1,3 +1,3 @@
1
1
  module Canfig
2
- VERSION = '0.0.9'
2
+ VERSION = '0.0.14'
3
3
  end
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.9
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: 2020-12-30 00:00:00.000000000 Z
11
+ date: 2021-01-01 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activesupport