env_vars 0.7.1 → 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.travis.yml +3 -6
- data/README.md +20 -0
- data/env_vars.gemspec +2 -1
- data/env_vars.png +0 -0
- data/env_vars.svg +14 -16
- data/lib/env_vars.rb +23 -13
- metadata +19 -5
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 55e64c1a12f68fdce3e66fbf0fe6206bf30d5efa934f79a813c83ad49d5642ba
|
4
|
+
data.tar.gz: 9fbc815998275bcdd4fc6a23f6fb7be0f856fdae42abe7b4795c56d46803c793
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: c5bc9f04749be125c623730228c0ea332cb0645636a9f0c5415d32f02ba287970713b0cc3f03e582afaace73b7bd8721579b4f6caf2be629f1fe72b76f46f806
|
7
|
+
data.tar.gz: 2d2631747255512e9794a4fc3f3638622995e28a78d725fd31b4b2b3d1457bd4be2434aa0dde4bb286eca5dc6092dc8172759556184a469e8c902d61b195d007
|
data/.travis.yml
CHANGED
@@ -4,16 +4,13 @@ sudo: false
|
|
4
4
|
notifications:
|
5
5
|
email: false
|
6
6
|
rvm:
|
7
|
-
- 2.5.
|
8
|
-
- 2.4.2
|
9
|
-
- 2.3.8
|
10
|
-
before_install: gem install bundler
|
7
|
+
- 2.5.3
|
11
8
|
before_script:
|
12
9
|
- curl -L https://codeclimate.com/downloads/test-reporter/test-reporter-latest-linux-amd64 > ./cc-test-reporter
|
13
10
|
- chmod +x ./cc-test-reporter
|
14
11
|
- "./cc-test-reporter before-build"
|
15
12
|
after_script:
|
16
|
-
- "./cc-test-reporter after-build --
|
13
|
+
- "./cc-test-reporter after-build --exit-code $TRAVIS_TEST_RESULT"
|
17
14
|
env:
|
18
15
|
global:
|
19
|
-
secure:
|
16
|
+
secure: dXC3R4mvHkeXyhKskgf5/3/LUtBYKpDcTpNGbuOpnoXAaB87fHgjhDtwSazYERE5i0FYeMHWBWKUosQZkCOCydXCuZQ7Q1AnqjnouiCoaj675uvs/KamRAoknQVzxbSk5nxSiqth2fMDu6DTm8ZcbAXkCJj3JwNe0x/zZrx6ZfqEj928NdL2qxTbGLciFyovjhjwIx5ZNKJ+LlvwZ5uGdaGJvN1K7xuATcrRFyyPRzd0oPGFJb7pBwbkK0VxmdTMKcCnXmovoIIZPsXCMW1zvfE30McrCOyHrE/4OQWFI0FG7QJAzM3ekioWQj94JRkno3NPflTWBqn+tSQmjgKkSuooJQgbJ0eWAD0uU2JBebjrXx4/AvWlUiB4mG4u7OGUbq8TbY2EHhqb5JtTuAo3qy/D5xUtZaSISD70sQqfE6ZdjVlBaC9hDSATYXNyiUYGihslEUySmCqH94ZBkm1c5CKDPm1bnBs8eyzI2NqO6EA/yf8/U97fGKI1EmjNQm888MIgbgSeKlWfc6EonWMxlaZ8SG/J4cFx43nlUPPmP/q488wKz8qaCeVpvuX29mN+8LQmQT0zQlVNZIHfI64tIcdE8kvK/vu+9iq7UlPim2VPNf8B9aHX67NUli0FVo2acvCgivIcZ75YJFSCmy8IhNX/XaJD5AdQgVmwP0A/uk0=
|
data/README.md
CHANGED
@@ -39,6 +39,16 @@ Config.timeout
|
|
39
39
|
Config.force_ssl?
|
40
40
|
```
|
41
41
|
|
42
|
+
You can specify the description for both `mandatory` and `optional` methods; this will be used in exceptions.
|
43
|
+
|
44
|
+
```ruby
|
45
|
+
Config = Env::Vars.new do
|
46
|
+
mandatory :missing_var, string, description: "this is important"
|
47
|
+
end
|
48
|
+
|
49
|
+
#=> Env::Vars::MissingEnvironmentVariable: MISSING_VAR (this is important) is not defined
|
50
|
+
```
|
51
|
+
|
42
52
|
If you're going to use `env_vars` as your main configuration object, you can also set arbitrary properties, like the following:
|
43
53
|
|
44
54
|
```ruby
|
@@ -61,6 +71,16 @@ Config = Env::Vars.new do
|
|
61
71
|
end
|
62
72
|
```
|
63
73
|
|
74
|
+
You may want to start a debug session without raising exceptions for missing variables. In this case, just pass `raise_exception: false` instead to log error messages to `$stderr`. This is especially great with Rails' credentials command (`rails credentials:edit`) when already defined the configuration.
|
75
|
+
|
76
|
+
```ruby
|
77
|
+
Config = Env::Vars.new(raise_exception: false) do
|
78
|
+
mandatory :database_url, string, description: "the leader database"
|
79
|
+
end
|
80
|
+
|
81
|
+
#=> [ENV_VARS] DATABASE_URL (the leader database) is not defined
|
82
|
+
```
|
83
|
+
|
64
84
|
### Types
|
65
85
|
|
66
86
|
You can coerce values to the following types:
|
data/env_vars.gemspec
CHANGED
@@ -16,8 +16,9 @@ Gem::Specification.new do |spec|
|
|
16
16
|
spec.require_paths = ["lib"]
|
17
17
|
|
18
18
|
spec.add_development_dependency "bundler"
|
19
|
-
spec.add_development_dependency "rake"
|
20
19
|
spec.add_development_dependency "minitest"
|
21
20
|
spec.add_development_dependency "minitest-utils"
|
21
|
+
spec.add_development_dependency "pry-meta"
|
22
|
+
spec.add_development_dependency "rake"
|
22
23
|
spec.add_development_dependency "simplecov"
|
23
24
|
end
|
data/env_vars.png
CHANGED
Binary file
|
data/env_vars.svg
CHANGED
@@ -1,22 +1,20 @@
|
|
1
1
|
<svg xmlns="http://www.w3.org/2000/svg" width="300" height="300" viewBox="0 0 300 300">
|
2
2
|
<g fill="none" fill-rule="evenodd">
|
3
3
|
<rect width="155" height="63" x="73" y="92" fill="#9013FE"/>
|
4
|
+
<rect width="154.839" height="9.714" x="72.581" y="126.286" fill="#000"/>
|
5
|
+
<rect width="62.903" height="9.714" x="164.516" y="145.714" fill="#000"/>
|
6
|
+
<rect width="62.903" height="9.714" x="72.581" y="145.714" fill="#000"/>
|
7
|
+
<rect width="62.903" height="9.714" x="164.516" y="106.857" fill="#000"/>
|
8
|
+
<rect width="62.903" height="9.714" x="72.581" y="106.857" fill="#000"/>
|
9
|
+
<rect width="154.839" height="9.714" x="72.581" y="87.429" fill="#000"/>
|
10
|
+
<path fill="#000" fill-rule="nonzero" d="M283.483871,0 L14.516129,0 C6.51290323,0 0,6.53771429 0,14.5714286 L0,238 L217.741935,238 L217.741935,228.285714 L9.67741935,228.285714 L9.67741935,48.5714286 L290.322581,48.5714286 L290.322581,228.285714 L217.741935,228.285714 L217.741935,238 L300,238 L300,14.5714286 C300,6.53771429 291.487097,0 283.483871,0 Z M9.67741935,38.8571429 L9.67741935,14.5714286 C9.67741935,11.8951429 11.85,9.71428571 14.516129,9.71428571 L285.483871,9.71428571 C288.15,9.71428571 290.322581,11.8951429 290.322581,14.5714286 L290.322581,38.8571429 L9.67741935,38.8571429 Z"/>
|
4
11
|
<path fill="#9013FE" d="M163.908393,300 L137.091607,300 L134.078214,287.931964 C130.211429,286.789286 126.479643,285.236786 122.92625,283.303393 L112.251607,289.70625 L93.29375,270.748393 L99.6966071,260.07375 C97.7632143,256.520357 96.2107143,252.78375 95.0680357,248.921786 L83,245.908393 L83,219.091607 L95.0680357,216.078214 C96.2107143,212.211429 97.7632143,208.479643 99.6966071,204.92625 L93.29375,194.251607 L112.251607,175.29375 L122.92625,181.696607 C126.479643,179.763214 130.21625,178.210714 134.078214,177.068036 L137.091607,165 L163.908393,165 L166.921786,177.068036 C170.788571,178.210714 174.520357,179.763214 178.07375,181.696607 L188.748393,175.29375 L207.70625,194.251607 L201.303393,204.92625 C203.236786,208.479643 204.789286,212.21625 205.931964,216.078214 L218,219.091607 L218,245.908393 L205.931964,248.921786 C204.789286,252.788571 203.236786,256.520357 201.303393,260.07375 L207.70625,270.748393 L188.748393,289.70625 L178.07375,283.303393 C174.520357,285.236786 170.78375,286.789286 166.921786,287.931964 L163.908393,300 Z"/>
|
5
|
-
<
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
<path fill-rule="nonzero" d="M150,213.714286 C139.325806,213.714286 130.645161,222.428 130.645161,233.142857 C130.645161,243.857714 139.325806,252.571429 150,252.571429 C160.674194,252.571429 169.354839,243.857714 169.354839,233.142857 C169.354839,222.428 160.674194,213.714286 150,213.714286 Z M150,242.857143 C144.662903,242.857143 140.322581,238.500286 140.322581,233.142857 C140.322581,227.785429 144.662903,223.428571 150,223.428571 C155.337097,223.428571 159.677419,227.785429 159.677419,233.142857 C159.677419,238.500286 155.337097,242.857143 150,242.857143 Z"/>
|
13
|
-
<path d="M150 194.285714C143.574194 194.285714 137.201613 195.903143 131.579032 198.958286L136.190323 207.502C140.404839 205.214286 145.175806 204 150 204 166.01129 204 179.032258 217.070571 179.032258 233.142857 179.032258 237.985429 177.822581 242.774571 175.543548 247.005143L184.054839 251.634C187.098387 245.99 188.709677 239.593143 188.709677 233.142857 188.709677 211.718 171.343548 194.285714 150 194.285714zM150 262.285714C133.98871 262.285714 120.967742 249.215143 120.967742 233.142857 120.967742 228.300286 122.177419 223.511143 124.456452 219.280571L115.945161 214.651714C112.901613 220.295714 111.290323 226.692571 111.290323 233.142857 111.290323 254.567714 128.656452 272 150 272 156.425806 272 162.798387 270.382571 168.420968 267.327429L163.809677 258.783714C159.595161 261.071429 154.824194 262.285714 150 262.285714z"/>
|
14
|
-
<path fill-rule="nonzero" d="M285.483871,0 L14.516129,0 C6.51290323,0 0,6.53771429 0,14.5714286 L0,238 L82.2580645,238 L82.2580645,228.285714 L9.67741935,228.285714 L9.67741935,48.5714286 L290.322581,48.5714286 L290.322581,228.285714 L217.741935,228.285714 L217.741935,238 L300,238 L300,14.5714286 C300,6.53771429 293.487097,0 285.483871,0 Z M9.67741935,38.8571429 L9.67741935,14.5714286 C9.67741935,11.8951429 11.85,9.71428571 14.516129,9.71428571 L285.483871,9.71428571 C288.15,9.71428571 290.322581,11.8951429 290.322581,14.5714286 L290.322581,38.8571429 L9.67741935,38.8571429 Z"/>
|
15
|
-
<rect width="9.677" height="9.714" x="19.355" y="19.429"/>
|
16
|
-
<rect width="9.677" height="9.714" x="38.71" y="19.429"/>
|
17
|
-
<rect width="9.677" height="9.714" x="58.065" y="19.429"/>
|
18
|
-
<polygon points="45 187.289 45 60 68.99 60 68.99 73.227 58.504 73.694 58.504 173.439 68.99 174.062 68.99 187.289"/>
|
19
|
-
<polygon points="255.99 187.412 232 187.412 232 174.277 242.486 173.658 242.486 74.599 232 74.136 232 61 255.99 61"/>
|
20
|
-
</g>
|
12
|
+
<path fill="#000" fill-rule="nonzero" d="M150,213.714286 C139.325806,213.714286 130.645161,222.428 130.645161,233.142857 C130.645161,243.857714 139.325806,252.571429 150,252.571429 C160.674194,252.571429 169.354839,243.857714 169.354839,233.142857 C169.354839,222.428 160.674194,213.714286 150,213.714286 Z M150,242.857143 C144.662903,242.857143 140.322581,238.500286 140.322581,233.142857 C140.322581,227.785429 144.662903,223.428571 150,223.428571 C155.337097,223.428571 159.677419,227.785429 159.677419,233.142857 C159.677419,238.500286 155.337097,242.857143 150,242.857143 Z"/>
|
13
|
+
<path fill="#000" d="M150 194.285714C143.574194 194.285714 137.201613 195.903143 131.579032 198.958286L136.190323 207.502C140.404839 205.214286 145.175806 204 150 204 166.01129 204 179.032258 217.070571 179.032258 233.142857 179.032258 237.985429 177.822581 242.774571 175.543548 247.005143L184.054839 251.634C187.098387 245.99 188.709677 239.593143 188.709677 233.142857 188.709677 211.718 171.343548 194.285714 150 194.285714zM150 262.285714C133.98871 262.285714 120.967742 249.215143 120.967742 233.142857 120.967742 228.300286 122.177419 223.511143 124.456452 219.280571L115.945161 214.651714C112.901613 220.295714 111.290323 226.692571 111.290323 233.142857 111.290323 254.567714 128.656452 272 150 272 156.425806 272 162.798387 270.382571 168.420968 267.327429L163.809677 258.783714C159.595161 261.071429 154.824194 262.285714 150 262.285714z"/>
|
14
|
+
<rect width="9.677" height="9.714" x="19.355" y="19.429" fill="#000"/>
|
15
|
+
<rect width="9.677" height="9.714" x="38.71" y="19.429" fill="#000"/>
|
16
|
+
<rect width="9.677" height="9.714" x="58.065" y="19.429" fill="#000"/>
|
17
|
+
<polygon fill="#000" points="45 187.289 45 60 68.99 60 68.99 73.227 58.504 73.694 58.504 173.439 68.99 174.062 68.99 187.289"/>
|
18
|
+
<polygon fill="#000" points="255.99 187.412 232 187.412 232 174.277 242.486 173.658 242.486 74.599 232 74.136 232 61 255.99 61"/>
|
21
19
|
</g>
|
22
20
|
</svg>
|
data/lib/env_vars.rb
CHANGED
@@ -1,16 +1,16 @@
|
|
1
|
-
# frozen_string_literal: true
|
2
|
-
|
3
1
|
module Env
|
4
2
|
class Vars
|
5
|
-
VERSION = "0.
|
3
|
+
VERSION = "1.0.0"
|
6
4
|
BOOL_TRUE = ["yes", "true", "1", true]
|
7
5
|
BOOL_FALSE = ["no", "false"]
|
8
6
|
|
9
7
|
MissingEnvironmentVariable = Class.new(StandardError)
|
10
8
|
MissingCallable = Class.new(StandardError)
|
11
9
|
|
12
|
-
def initialize(env
|
10
|
+
def initialize(env: ENV, raise_exception: true, stderr: $stderr, &block)
|
13
11
|
@env = env
|
12
|
+
@raise_exception = raise_exception
|
13
|
+
@stderr = stderr
|
14
14
|
@__cache__ = {}
|
15
15
|
instance_eval(&block)
|
16
16
|
end
|
@@ -20,12 +20,12 @@ module Env
|
|
20
20
|
end
|
21
21
|
alias_method :inspect, :to_s
|
22
22
|
|
23
|
-
def set(name, type, default = nil, required: false, aliases: [])
|
23
|
+
def set(name, type, default = nil, required: false, aliases: [], description: nil)
|
24
24
|
name = name.to_s
|
25
25
|
env_var = name.upcase
|
26
26
|
name = "#{name}?" if type == bool
|
27
27
|
|
28
|
-
validate!(env_var, required)
|
28
|
+
validate!(env_var, required, description)
|
29
29
|
|
30
30
|
define_singleton_method(name) do
|
31
31
|
return default unless @env.key?(env_var)
|
@@ -37,20 +37,30 @@ module Env
|
|
37
37
|
end
|
38
38
|
end
|
39
39
|
|
40
|
-
def validate!(env_var, required)
|
40
|
+
def validate!(env_var, required, description)
|
41
41
|
return unless required
|
42
|
-
|
42
|
+
return if @env.key?(env_var)
|
43
|
+
|
44
|
+
message = env_var.to_s
|
45
|
+
message << " (#{description})" if description
|
46
|
+
message << " is not defined."
|
47
|
+
|
48
|
+
raise MissingEnvironmentVariable, message if @raise_exception
|
49
|
+
|
50
|
+
message = "[ENV_VARS] #{message}"
|
51
|
+
message = "\e[31m#{message}\e[0m" if @stderr.tty?
|
52
|
+
@stderr << message << "\n"
|
43
53
|
end
|
44
54
|
|
45
|
-
def mandatory(name, type, aliases: [])
|
46
|
-
set(name, type, required: true, aliases: aliases)
|
55
|
+
def mandatory(name, type, aliases: [], description: nil)
|
56
|
+
set(name, type, required: true, aliases: aliases, description: description)
|
47
57
|
end
|
48
58
|
|
49
|
-
def optional(name, type, default = nil, aliases: [])
|
50
|
-
set(name, type, default, aliases: aliases)
|
59
|
+
def optional(name, type, default = nil, aliases: [], description: nil)
|
60
|
+
set(name, type, default, aliases: aliases, description: description)
|
51
61
|
end
|
52
62
|
|
53
|
-
def property(name, func = nil, cache: true, &block)
|
63
|
+
def property(name, func = nil, cache: true, description: nil, &block)
|
54
64
|
callable = (func || block)
|
55
65
|
raise MissingCallable, "arg[1] must respond to #call or pass a block" unless callable
|
56
66
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: env_vars
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 1.0.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Nando Vieira
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2018-12-
|
11
|
+
date: 2018-12-11 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -25,7 +25,7 @@ dependencies:
|
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '0'
|
27
27
|
- !ruby/object:Gem::Dependency
|
28
|
-
name:
|
28
|
+
name: minitest
|
29
29
|
requirement: !ruby/object:Gem::Requirement
|
30
30
|
requirements:
|
31
31
|
- - ">="
|
@@ -39,7 +39,7 @@ dependencies:
|
|
39
39
|
- !ruby/object:Gem::Version
|
40
40
|
version: '0'
|
41
41
|
- !ruby/object:Gem::Dependency
|
42
|
-
name: minitest
|
42
|
+
name: minitest-utils
|
43
43
|
requirement: !ruby/object:Gem::Requirement
|
44
44
|
requirements:
|
45
45
|
- - ">="
|
@@ -53,7 +53,21 @@ dependencies:
|
|
53
53
|
- !ruby/object:Gem::Version
|
54
54
|
version: '0'
|
55
55
|
- !ruby/object:Gem::Dependency
|
56
|
-
name:
|
56
|
+
name: pry-meta
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ">="
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '0'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ">="
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
57
71
|
requirement: !ruby/object:Gem::Requirement
|
58
72
|
requirements:
|
59
73
|
- - ">="
|