env_bang 0.2.2 → 0.2.3
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/env_bang/version.rb +1 -1
- data/lib/env_bang.rb +7 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 287b06064bf43d1929be703bf94162da9410405e
|
4
|
+
data.tar.gz: af7afbcc9e86a6b49a8f707d30f36f72a69f0c51
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 34468725fcb5025f66a3f07465c23c1a2339954f1437354867c9c6d4593715a053d79bccad4d38fa13a113cbee0988d33259931504c3911cd7b8c93b901dc13d
|
7
|
+
data.tar.gz: f3d75bd63a8a9bae881e44f11bfc7d718e90a508dbb398eec0a79801a4a79ff3abaa3d551e8b1701e1e08f2139587d650ba39a9fd3692cb91262a7299f4cddbf
|
data/lib/env_bang/version.rb
CHANGED
data/lib/env_bang.rb
CHANGED
@@ -14,9 +14,7 @@ class ENV_BANG
|
|
14
14
|
ENV[var] = options.fetch(:default) { formatted_error(var, description) }.to_s
|
15
15
|
end
|
16
16
|
|
17
|
-
|
18
|
-
klass = :"#{options.fetch(:class, :StringUnlessFalsey)}"
|
19
|
-
vars[var] = Classes.cast ENV[var], klass, options
|
17
|
+
vars[var] = options
|
20
18
|
end
|
21
19
|
|
22
20
|
def formatted_error(var, description)
|
@@ -33,7 +31,7 @@ class ENV_BANG
|
|
33
31
|
def [](var)
|
34
32
|
raise KeyError.new("ENV_BANG is not configured to use var #{var}") unless vars.has_key?(var)
|
35
33
|
|
36
|
-
vars[var]
|
34
|
+
Classes.cast ENV[var], vars[var]
|
37
35
|
end
|
38
36
|
|
39
37
|
def method_missing(method, *args, &block)
|
@@ -43,8 +41,8 @@ class ENV_BANG
|
|
43
41
|
|
44
42
|
module Classes
|
45
43
|
class << self
|
46
|
-
def cast(value,
|
47
|
-
public_send(:"#{
|
44
|
+
def cast(value, options = {})
|
45
|
+
public_send(:"#{options.fetch(:class, :StringUnlessFalsey)}", value, options)
|
48
46
|
end
|
49
47
|
|
50
48
|
def boolean(value, options)
|
@@ -52,8 +50,9 @@ class ENV_BANG
|
|
52
50
|
end
|
53
51
|
|
54
52
|
def Array(value, options)
|
55
|
-
|
56
|
-
|
53
|
+
options.delete(:class)
|
54
|
+
options[:class] = options[:of] if options[:of]
|
55
|
+
value.split(',').map { |value| cast(value.strip, options) }
|
57
56
|
end
|
58
57
|
|
59
58
|
def Symbol(value, options)
|