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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 55f77b7c37c5f38cc2d89f6564976aeb3e71dee8
4
- data.tar.gz: 6e84440c64a0ea51fcc2a9be15a2a78f64506b77
3
+ metadata.gz: f4f947f6254ba2525e9adbc54f9232f3ad474d87
4
+ data.tar.gz: 1d841d62033d1de759c785df8ff4777e70021fcc
5
5
  SHA512:
6
- metadata.gz: b02a627cd7bc398627292834eff7efda1b8938bce66722d37e33d61f157a196f1da4abd6271fd4eba6c2ae766f0546b53acece6568a865a094d91a436425eb87
7
- data.tar.gz: 2cc8df056e3b654eb50cc0ab25a0cea4c64cf119d0420c6337a6cc0720affbfa59d29a5a65fdb3555bfd8d605c190c9c4056fe49493e62d925de11e1c8c3c85c
6
+ metadata.gz: 00714c51d0c558d9dc4b6fe9f34bd1e2e50ea99ce02123e841ac5c616b7c1250ef8d856e141ace7f92b8dab817b2c3bd84cfaa1f39c2637730f27ee1bc859311
7
+ data.tar.gz: c65bdc677a552e3dcd82ffdf915922a076b9067348ce81bd28fa15469524bad00ad37213c310ed95063c7a4c27b55da6091df4de99c58aeaa7136ffa6a3c619e
@@ -1,3 +1,3 @@
1
1
  class ENV_BANG
2
- VERSION = "0.2.1"
2
+ VERSION = "0.2.2"
3
3
  end
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, :StringUnlessEmpty)}"
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, :StringUnlessEmpty)
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 StringUnlessEmpty(value, options)
64
- value.length > 0 ? value : nil
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
@@ -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 false" do
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 an empty string to nil by default" do
114
- ENV['NIL'] = ''
115
- ENV!.use 'NIL'
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!['NIL'].must_be_nil
117
+ ENV!['FALSE'].must_equal false
118
118
  end
119
119
 
120
- it "leaves an empty string as String if specified" do
121
- ENV['EMPTY_STRING'] = ''
122
- ENV!.use 'EMPTY_STRING', class: String
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!['EMPTY_STRING'].must_equal ''
124
+ ENV!['FALSE'].class.must_equal String
125
125
  end
126
126
  end
127
127
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: env_bang
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.2.1
4
+ version: 0.2.2
5
5
  platform: ruby
6
6
  authors:
7
7
  - Jonathan Camenisch