env_bang 0.2.1 → 0.2.2
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 +4 -4
- data/test/env_bang_test.rb +9 -9
- 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: f4f947f6254ba2525e9adbc54f9232f3ad474d87
|
4
|
+
data.tar.gz: 1d841d62033d1de759c785df8ff4777e70021fcc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 00714c51d0c558d9dc4b6fe9f34bd1e2e50ea99ce02123e841ac5c616b7c1250ef8d856e141ace7f92b8dab817b2c3bd84cfaa1f39c2637730f27ee1bc859311
|
7
|
+
data.tar.gz: c65bdc677a552e3dcd82ffdf915922a076b9067348ce81bd28fa15469524bad00ad37213c310ed95063c7a4c27b55da6091df4de99c58aeaa7136ffa6a3c619e
|
data/lib/env_bang/version.rb
CHANGED
data/lib/env_bang.rb
CHANGED
@@ -15,7 +15,7 @@ class ENV_BANG
|
|
15
15
|
end
|
16
16
|
|
17
17
|
# Store the variable, converted to requested class
|
18
|
-
klass = :"#{options.fetch(:class, :
|
18
|
+
klass = :"#{options.fetch(:class, :StringUnlessFalsey)}"
|
19
19
|
vars[var] = Classes.cast ENV[var], klass, options
|
20
20
|
end
|
21
21
|
|
@@ -52,7 +52,7 @@ class ENV_BANG
|
|
52
52
|
end
|
53
53
|
|
54
54
|
def Array(value, options)
|
55
|
-
klass = options.fetch(:of, :
|
55
|
+
klass = options.fetch(:of, :StringUnlessFalsey)
|
56
56
|
value.split(',').map { |value| cast(value.strip, klass) }
|
57
57
|
end
|
58
58
|
|
@@ -60,8 +60,8 @@ class ENV_BANG
|
|
60
60
|
value.to_sym
|
61
61
|
end
|
62
62
|
|
63
|
-
def
|
64
|
-
value
|
63
|
+
def StringUnlessFalsey(value, options)
|
64
|
+
boolean(value, options) && value
|
65
65
|
end
|
66
66
|
|
67
67
|
# Delegate methods like Integer(), Float(), String(), etc. to the Kernel module
|
data/test/env_bang_test.rb
CHANGED
@@ -96,7 +96,7 @@ describe ENV_BANG do
|
|
96
96
|
ENV!['FLOATS'].must_equal floats.map(&:to_f)
|
97
97
|
end
|
98
98
|
|
99
|
-
it "Casts
|
99
|
+
it "Casts true" do
|
100
100
|
ENV['TRUE'] = truthy_values.sample
|
101
101
|
ENV!.use 'TRUE', class: :boolean
|
102
102
|
|
@@ -110,18 +110,18 @@ describe ENV_BANG do
|
|
110
110
|
ENV!['FALSE'].must_equal false
|
111
111
|
end
|
112
112
|
|
113
|
-
it "converts
|
114
|
-
ENV['
|
115
|
-
ENV!.use '
|
113
|
+
it "converts falsey or empty string to false by default" do
|
114
|
+
ENV['FALSE'] = falsey_values.sample
|
115
|
+
ENV!.use 'FALSE'
|
116
116
|
|
117
|
-
ENV!['
|
117
|
+
ENV!['FALSE'].must_equal false
|
118
118
|
end
|
119
119
|
|
120
|
-
it "leaves
|
121
|
-
ENV['
|
122
|
-
ENV!.use '
|
120
|
+
it "leaves falsey string as string if specified" do
|
121
|
+
ENV['FALSE'] = falsey_values.sample
|
122
|
+
ENV!.use 'FALSE', class: String
|
123
123
|
|
124
|
-
ENV!['
|
124
|
+
ENV!['FALSE'].class.must_equal String
|
125
125
|
end
|
126
126
|
end
|
127
127
|
end
|