envee 0.0.3 → 0.0.4

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,15 +1,7 @@
1
1
  ---
2
- !binary "U0hBMQ==":
3
- metadata.gz: !binary |-
4
- MzJmNzRjZWEzNTQxNDkyMmU0MzZjYmZlNmNjYTE3OGY1YzliNzJhNg==
5
- data.tar.gz: !binary |-
6
- MDMyMzllZmVlODk1MjgxYzQxNjg0MWIyZmE1YzkwOTNhNTFmODhiNQ==
2
+ SHA1:
3
+ metadata.gz: f479aedd1066f6b181c5391ae2fe3611ea98a823
4
+ data.tar.gz: 11cb01c5f92bef72126dbf7aed6d95ec373df55c
7
5
  SHA512:
8
- metadata.gz: !binary |-
9
- MDhhNzQxOGI2NjQ4NzFhOGZmZDNkZjc3ZGYyMDg3Y2U5ZGM2NTMyYTZlMTFh
10
- YjIxOTkyYjdjODg2ZTdkY2M0OGJlZTNhZGZiNzNmYWFiNjY3NTI2NGMwZWI4
11
- YWZjMWVlMWI2OTc4ZTQwODc4YTA4NWE2YjQyNGE3YTVkYzVmZTg=
12
- data.tar.gz: !binary |-
13
- OWJjYzY4YjBmNTBmMzQwNDhlN2RiYTgyMTJjZTY3ZmNiNmU0NjRhYmQ5YWE3
14
- NzVhZjU5YWUwMzBiMmRiOGNjOGM5YTZkYmNkODI3ZmJlY2E4YTEyY2JlNjdh
15
- NjNmYzVhMzE3MjIzODc2OGIxNDIyYTc0ZTI5MTAwYmExMjk4Y2E=
6
+ metadata.gz: a1d85e394ff8fc1bd746e46e3a671c93a0689c9110eb9768a93ee035670ec4e28566c8b9d3634d0721a24577a4f18918c95626bd0ab0a1a6600a59c3b978c5f0
7
+ data.tar.gz: 6016549dae3162d96b2d2086f695df57241adc2d75a2e36dd7585d15ac32b7caea9e2ca140bb0ca3dd746ab6cf7a8c3c884ac65a29907d4cd58f2a3fa044aeed
@@ -13,38 +13,76 @@ module Envee
13
13
  end
14
14
  end
15
15
 
16
+ class MissingValueError < StandardError
17
+ def initialize(key)
18
+ super("Environment variable had no value: #{key.inspect}")
19
+ end
20
+ end
21
+
22
+ class UncoercibleError < StandardError
23
+ def initialize(key, type)
24
+ super("Unable to coerce environment variable #{key.inspect} to #{type}")
25
+ end
26
+ end
27
+
16
28
  def int(*args, &block)
17
29
  Integer(fetch(*args, &block))
30
+ rescue ArgumentError
31
+ raise UncoercibleError.new(args.first, 'Integer')
32
+ rescue KeyError
33
+ raise MissingValueError.new(args.first)
18
34
  end
19
35
 
20
36
  def fl(*args, &block)
21
37
  Float(fetch(*args, &block))
38
+ rescue ArgumentError
39
+ raise UncoercibleError.new(args.first, 'Float')
40
+ rescue KeyError
41
+ raise MissingValueError.new(args.first)
22
42
  end
23
43
 
24
44
  def str(*args, &block)
25
45
  String(fetch(*args, &block))
46
+ rescue ArgumentError
47
+ raise UncoercibleError.new(args.first, 'String')
48
+ rescue KeyError
49
+ raise MissingValueError.new(args.first)
26
50
  end
27
51
 
28
52
  def sym(*args, &block)
29
53
  String(fetch(*args, &block)).to_sym
54
+ rescue ArgumentError
55
+ raise UncoercibleError.new(args.first, 'Symbol')
56
+ rescue KeyError
57
+ raise MissingValueError.new(args.first)
30
58
  end
31
59
 
32
60
  def bool(*args, &block)
33
61
  value = fetch(*args, &block)
34
62
 
35
63
  value && value !~ /\A(0|no|false|off|nil|null|)\z/i
64
+ rescue KeyError
65
+ raise MissingValueError.new(args.first)
36
66
  end
37
67
 
38
68
  def time(*args, &block)
39
69
  value = fetch(*args, &block)
40
70
  return value if value.is_a?(Time)
41
71
  Time.parse(value).utc
72
+ rescue ArgumentError
73
+ raise UncoercibleError.new(args.first, 'Time')
74
+ rescue KeyError
75
+ raise MissingValueError.new(args.first)
42
76
  end
43
77
 
44
78
  def int_time(*args, &block)
45
79
  value = Integer(fetch(*args, &block))
46
80
  return value if value.is_a?(Time)
47
81
  Time.at(value).utc
82
+ rescue ArgumentError
83
+ raise UncoercibleError.new(args.first, 'Integer')
84
+ rescue KeyError
85
+ raise MissingValueError.new(args.first)
48
86
  end
49
87
 
50
88
  def validate!(options = {})
@@ -1,4 +1,4 @@
1
1
  # Version
2
2
  module Envee
3
- VERSION = '0.0.3'
3
+ VERSION = '0.0.4'
4
4
  end
@@ -28,15 +28,15 @@ describe Envee do
28
28
  end
29
29
 
30
30
  context 'when requesting a value not in env with no default' do
31
- it 'raises an KeyError' do
32
- expect{env.int('NUM')}.to raise_error(KeyError)
31
+ it 'raises an MissingValueError' do
32
+ expect{env.int('NUM')}.to raise_error(Envee::MissingValueError, 'Environment variable had no value: "NUM"')
33
33
  end
34
34
  end
35
35
 
36
36
  context 'when requesting a value in env that cannot be casted to integer' do
37
- it 'raises an ArgumentError' do
37
+ it 'raises an UncoercibleError' do
38
38
  env['NUM'] = 'a'
39
- expect{env.int('NUM')}.to raise_error(ArgumentError)
39
+ expect{env.int('NUM')}.to raise_error(Envee::UncoercibleError, 'Unable to coerce environment variable "NUM" to Integer')
40
40
  end
41
41
  end
42
42
  end
@@ -62,15 +62,15 @@ describe Envee do
62
62
  end
63
63
 
64
64
  context 'when requesting a value not in env with no default' do
65
- it 'raises an KeyError' do
66
- expect{env.fl('NUM')}.to raise_error(KeyError)
65
+ it 'raises an MissingValueError' do
66
+ expect{env.fl('NUM')}.to raise_error(Envee::MissingValueError, 'Environment variable had no value: "NUM"')
67
67
  end
68
68
  end
69
69
 
70
70
  context 'when requesting a value in env that cannot be casted to float' do
71
- it 'raises an ArgumentError' do
71
+ it 'raises an UncoercibleError' do
72
72
  env['NUM'] = 'a'
73
- expect{env.fl('NUM')}.to raise_error(ArgumentError)
73
+ expect{env.fl('NUM')}.to raise_error(Envee::UncoercibleError, 'Unable to coerce environment variable "NUM" to Float')
74
74
  end
75
75
  end
76
76
  end
@@ -96,8 +96,8 @@ describe Envee do
96
96
  end
97
97
 
98
98
  context 'when requesting a value not in env with no default' do
99
- it 'raises an KeyError' do
100
- expect{env.str('NUM')}.to raise_error(KeyError)
99
+ it 'raises an MissingValueError' do
100
+ expect{env.str('NUM')}.to raise_error(Envee::MissingValueError, 'Environment variable had no value: "NUM"')
101
101
  end
102
102
  end
103
103
  end
@@ -123,8 +123,8 @@ describe Envee do
123
123
  end
124
124
 
125
125
  context 'when requesting a value not in env with no default' do
126
- it 'raises an KeyError' do
127
- expect{env.sym('NUM')}.to raise_error(KeyError)
126
+ it 'raises an MissingValueError' do
127
+ expect{env.sym('NUM')}.to raise_error(Envee::MissingValueError, 'Environment variable had no value: "NUM"')
128
128
  end
129
129
  end
130
130
  end
@@ -159,8 +159,8 @@ describe Envee do
159
159
  end
160
160
 
161
161
  context 'when requesting a value not in env with no default' do
162
- it 'raises an KeyError' do
163
- expect{env.bool('START')}.to raise_error(KeyError)
162
+ it 'raises an MissingValueError' do
163
+ expect{env.bool('START')}.to raise_error(Envee::MissingValueError, 'Environment variable had no value: "START"')
164
164
  end
165
165
  end
166
166
  end
@@ -192,15 +192,15 @@ describe Envee do
192
192
  end
193
193
 
194
194
  context 'when requesting a value not in env with no default' do
195
- it 'raises an KeyError' do
196
- expect{env.time('TIME')}.to raise_error(KeyError)
195
+ it 'raises an MissingValueError' do
196
+ expect{env.time('TIME')}.to raise_error(Envee::MissingValueError, 'Environment variable had no value: "TIME"')
197
197
  end
198
198
  end
199
199
 
200
200
  context 'when requesting a value in env that cannot be casted to time' do
201
- it 'raises an ArgumentError' do
201
+ it 'raises an UncoercibleError' do
202
202
  env['TIME'] = 'a'
203
- expect{env.time('TIME')}.to raise_error(ArgumentError)
203
+ expect{env.time('TIME')}.to raise_error(Envee::UncoercibleError, 'Unable to coerce environment variable "TIME" to Time')
204
204
  end
205
205
  end
206
206
  end
@@ -226,15 +226,15 @@ describe Envee do
226
226
  end
227
227
 
228
228
  context 'when requesting a value not in env with no default' do
229
- it 'raises an KeyError' do
230
- expect{env.int_time('TIME')}.to raise_error(KeyError)
229
+ it 'raises an MissingValueError' do
230
+ expect{env.int_time('TIME')}.to raise_error(Envee::MissingValueError, 'Environment variable had no value: "TIME"')
231
231
  end
232
232
  end
233
233
 
234
234
  context 'when requesting a value in env that cannot be casted to time' do
235
- it 'raises an ArgumentError' do
235
+ it 'raises an UncoercibleError' do
236
236
  env['TIME'] = 'a'
237
- expect{env.int_time('TIME')}.to raise_error(ArgumentError)
237
+ expect{env.int_time('TIME')}.to raise_error(Envee::UncoercibleError, 'Unable to coerce environment variable "TIME" to Integer')
238
238
  end
239
239
  end
240
240
  end
metadata CHANGED
@@ -1,55 +1,55 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: envee
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.3
4
+ version: 0.0.4
5
5
  platform: ruby
6
6
  authors:
7
7
  - Allen Madsen
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2015-12-01 00:00:00.000000000 Z
11
+ date: 2015-12-07 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ~>
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
19
  version: '1.7'
20
20
  type: :development
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ~>
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
26
  version: '1.7'
27
27
  - !ruby/object:Gem::Dependency
28
28
  name: rake
29
29
  requirement: !ruby/object:Gem::Requirement
30
30
  requirements:
31
- - - ~>
31
+ - - "~>"
32
32
  - !ruby/object:Gem::Version
33
33
  version: '10.0'
34
34
  type: :development
35
35
  prerelease: false
36
36
  version_requirements: !ruby/object:Gem::Requirement
37
37
  requirements:
38
- - - ~>
38
+ - - "~>"
39
39
  - !ruby/object:Gem::Version
40
40
  version: '10.0'
41
41
  - !ruby/object:Gem::Dependency
42
42
  name: rspec
43
43
  requirement: !ruby/object:Gem::Requirement
44
44
  requirements:
45
- - - ! '>='
45
+ - - ">="
46
46
  - !ruby/object:Gem::Version
47
47
  version: '0'
48
48
  type: :development
49
49
  prerelease: false
50
50
  version_requirements: !ruby/object:Gem::Requirement
51
51
  requirements:
52
- - - ! '>='
52
+ - - ">="
53
53
  - !ruby/object:Gem::Version
54
54
  version: '0'
55
55
  description:
@@ -59,9 +59,9 @@ executables: []
59
59
  extensions: []
60
60
  extra_rdoc_files: []
61
61
  files:
62
- - .gitignore
63
- - .rspec
64
- - .rubocop.yml
62
+ - ".gitignore"
63
+ - ".rspec"
64
+ - ".rubocop.yml"
65
65
  - Gemfile
66
66
  - LICENSE.txt
67
67
  - README.md
@@ -81,21 +81,20 @@ require_paths:
81
81
  - lib
82
82
  required_ruby_version: !ruby/object:Gem::Requirement
83
83
  requirements:
84
- - - ! '>='
84
+ - - ">="
85
85
  - !ruby/object:Gem::Version
86
86
  version: '0'
87
87
  required_rubygems_version: !ruby/object:Gem::Requirement
88
88
  requirements:
89
- - - ! '>='
89
+ - - ">="
90
90
  - !ruby/object:Gem::Version
91
91
  version: '0'
92
92
  requirements: []
93
93
  rubyforge_project:
94
- rubygems_version: 2.4.5
94
+ rubygems_version: 2.4.5.1
95
95
  signing_key:
96
96
  specification_version: 4
97
97
  summary: Provides casting wrappers around fetch for environment variables.
98
98
  test_files:
99
99
  - spec/envee_spec.rb
100
100
  - spec/spec_helper.rb
101
- has_rdoc: