env_vars 0.1.0 → 0.1.1
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/README.md +1 -0
- data/lib/env_vars.rb +10 -6
- 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: f8ea2051edc275de193a7cd56396e672fd56f081
|
4
|
+
data.tar.gz: eee02ef652b4dcd75f0da09550865bc46bca664f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: f6921934a70a78876d5fed00e4230043c22db2172d63b3122aedd4dbc57f9274030b034e12779a2c73f31c87112242447ddd4ae29e4784ca4ed593f4249d862e
|
7
|
+
data.tar.gz: efd20f2d3c21cf05d741119d50bea3d998c111f74589697f505032e835b8c22fd6afea20333be1b143ed2b70e7606d848f5486f7b1f29cfcad6aa5efe4e5e741
|
data/README.md
CHANGED
data/lib/env_vars.rb
CHANGED
@@ -1,6 +1,6 @@
|
|
1
1
|
module Env
|
2
2
|
class Vars
|
3
|
-
VERSION = '0.1.
|
3
|
+
VERSION = '0.1.1'
|
4
4
|
BOOL_TRUE = ['yes', 'true', '1', true]
|
5
5
|
BOOL_FALSE = ['no', 'false']
|
6
6
|
|
@@ -10,7 +10,7 @@ module Env
|
|
10
10
|
instance_eval(&block)
|
11
11
|
end
|
12
12
|
|
13
|
-
def set(name, type, default = nil, required: false)
|
13
|
+
def set(name, type, default = nil, required: false, aliases: [])
|
14
14
|
name = name.to_s
|
15
15
|
env_var = name.upcase
|
16
16
|
name = "#{name}?" if type == bool
|
@@ -29,18 +29,22 @@ module Env
|
|
29
29
|
value
|
30
30
|
end
|
31
31
|
end
|
32
|
+
|
33
|
+
aliases.each do |alias_name|
|
34
|
+
define_singleton_method(alias_name, method(name))
|
35
|
+
end
|
32
36
|
end
|
33
37
|
|
34
38
|
def validate!(env_var, required)
|
35
39
|
raise MissingEnvironmentVariable, "#{env_var} is not defined" if required && !ENV.key?(env_var)
|
36
40
|
end
|
37
41
|
|
38
|
-
def mandatory(name, type)
|
39
|
-
set(name, type, required: true)
|
42
|
+
def mandatory(name, type, aliases: [])
|
43
|
+
set(name, type, required: true, aliases: aliases)
|
40
44
|
end
|
41
45
|
|
42
|
-
def optional(name, type, default = nil)
|
43
|
-
set(name, type, default)
|
46
|
+
def optional(name, type, default = nil, aliases: [])
|
47
|
+
set(name, type, default, aliases: aliases)
|
44
48
|
end
|
45
49
|
|
46
50
|
def int
|