env_vars 1.1.0 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/FUNDING.yml +3 -0
- data/.gitignore +1 -0
- data/.rubocop.yml +3 -0
- data/README.md +17 -2
- data/env_vars.gemspec +4 -0
- data/lib/env_vars.rb +10 -1
- metadata +47 -4
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 878ff93d9458a5d4ca05b2b243128e76c84b42fbaf55fdd61e0c365213ffa9c2
|
4
|
+
data.tar.gz: 9934cb28319ac6f34922ef4873a3595956311c4aa8c409e0ae5e6c577e93817d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 123acdbada87a7cb5bec2f8a613bff62e4cf73dd5a833c3303d50fabb778ae49f287167195d2a785c6600c46e40471810f69ed67898a0bd65202d4584a25d835
|
7
|
+
data.tar.gz: 4d08d1a3d7d10a090c5214f5c00f943ea39a62789c54468f6bbc4f9d73e4f023c8901b743d87a8a96ddd43b587f3e63b6fb18f4e16e5529f55353c3434e94b47
|
data/.github/FUNDING.yml
ADDED
data/.gitignore
CHANGED
data/.rubocop.yml
CHANGED
data/README.md
CHANGED
@@ -1,9 +1,8 @@
|
|
1
|
-
![env_vars: Access environment variables. Also includes presence validation, type coercion and default values.](https://raw.githubusercontent.com/fnando/env_vars/
|
1
|
+
![env_vars: Access environment variables. Also includes presence validation, type coercion and default values.](https://raw.githubusercontent.com/fnando/env_vars/main/env_vars.png)
|
2
2
|
|
3
3
|
<p align="center">
|
4
4
|
<a href="https://travis-ci.org/fnando/env_vars"><img src="https://travis-ci.org/fnando/env_vars.svg" alt="Travis-CI"></a>
|
5
5
|
<a href="https://codeclimate.com/github/fnando/env_vars"><img src="https://codeclimate.com/github/fnando/env_vars/badges/gpa.svg" alt="Code Climate"></a>
|
6
|
-
<a href="https://codeclimate.com/github/fnando/env_vars/coverage"><img src="https://codeclimate.com/github/fnando/env_vars/badges/coverage.svg" alt="Test Coverage"></a>
|
7
6
|
<a href="https://rubygems.org/gems/env_vars"><img src="https://img.shields.io/gem/v/env_vars.svg" alt="Gem"></a>
|
8
7
|
<a href="https://rubygems.org/gems/env_vars"><img src="https://img.shields.io/gem/dt/env_vars.svg" alt="Gem"></a>
|
9
8
|
</p>
|
@@ -87,6 +86,22 @@ end
|
|
87
86
|
#=> [ENV_VARS] DATABASE_URL (the leader database) is not defined
|
88
87
|
```
|
89
88
|
|
89
|
+
I'd like to centralize access to my credentials; there's a handy mechanism for
|
90
|
+
doing that with `env_vars`:
|
91
|
+
|
92
|
+
```ruby
|
93
|
+
Config = Env::Vars.new do
|
94
|
+
credential :api_secret_key
|
95
|
+
credential :slack_oauth_credentials do |creds|
|
96
|
+
SlackCredentials.new(creds)
|
97
|
+
end
|
98
|
+
end
|
99
|
+
|
100
|
+
Config.api_secret_key
|
101
|
+
Config.slack_oauth_credentials
|
102
|
+
#=> The value stored under `Rails.application.credentials[:api_secret_key]`
|
103
|
+
```
|
104
|
+
|
90
105
|
### Types
|
91
106
|
|
92
107
|
You can coerce values to the following types:
|
data/env_vars.gemspec
CHANGED
@@ -7,6 +7,7 @@ Gem::Specification.new do |spec|
|
|
7
7
|
spec.version = Env::Vars::VERSION
|
8
8
|
spec.authors = ["Nando Vieira"]
|
9
9
|
spec.email = ["fnando.vieira@gmail.com"]
|
10
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 2.7.0")
|
10
11
|
|
11
12
|
spec.summary = "Access environment variables. Also includes presence " \
|
12
13
|
"validation, type coercion and default values."
|
@@ -24,6 +25,9 @@ Gem::Specification.new do |spec|
|
|
24
25
|
spec.add_development_dependency "minitest"
|
25
26
|
spec.add_development_dependency "minitest-utils"
|
26
27
|
spec.add_development_dependency "pry-meta"
|
28
|
+
spec.add_development_dependency "rails"
|
27
29
|
spec.add_development_dependency "rake"
|
30
|
+
spec.add_development_dependency "rubocop"
|
31
|
+
spec.add_development_dependency "rubocop-fnando"
|
28
32
|
spec.add_development_dependency "simplecov"
|
29
33
|
end
|
data/lib/env_vars.rb
CHANGED
@@ -2,7 +2,7 @@
|
|
2
2
|
|
3
3
|
module Env
|
4
4
|
class Vars
|
5
|
-
VERSION = "
|
5
|
+
VERSION = "2.0.0"
|
6
6
|
BOOL_TRUE = ["yes", "true", "1", true].freeze
|
7
7
|
BOOL_FALSE = %w[no false].freeze
|
8
8
|
|
@@ -92,6 +92,15 @@ module Env
|
|
92
92
|
end
|
93
93
|
end
|
94
94
|
|
95
|
+
def credential(name, &block)
|
96
|
+
define_singleton_method(name) do
|
97
|
+
@__cache__["_credential_#{name}".to_sym] ||= begin
|
98
|
+
value = Rails.application.credentials.fetch(name)
|
99
|
+
block ? block.call(value) : value # rubocop:disable Performance/RedundantBlockCall
|
100
|
+
end
|
101
|
+
end
|
102
|
+
end
|
103
|
+
|
95
104
|
def int
|
96
105
|
:int
|
97
106
|
end
|
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:
|
4
|
+
version: 2.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:
|
11
|
+
date: 2021-08-25 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|
@@ -66,6 +66,20 @@ dependencies:
|
|
66
66
|
- - ">="
|
67
67
|
- !ruby/object:Gem::Version
|
68
68
|
version: '0'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rails
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ">="
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ">="
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '0'
|
69
83
|
- !ruby/object:Gem::Dependency
|
70
84
|
name: rake
|
71
85
|
requirement: !ruby/object:Gem::Requirement
|
@@ -80,6 +94,34 @@ dependencies:
|
|
80
94
|
- - ">="
|
81
95
|
- !ruby/object:Gem::Version
|
82
96
|
version: '0'
|
97
|
+
- !ruby/object:Gem::Dependency
|
98
|
+
name: rubocop
|
99
|
+
requirement: !ruby/object:Gem::Requirement
|
100
|
+
requirements:
|
101
|
+
- - ">="
|
102
|
+
- !ruby/object:Gem::Version
|
103
|
+
version: '0'
|
104
|
+
type: :development
|
105
|
+
prerelease: false
|
106
|
+
version_requirements: !ruby/object:Gem::Requirement
|
107
|
+
requirements:
|
108
|
+
- - ">="
|
109
|
+
- !ruby/object:Gem::Version
|
110
|
+
version: '0'
|
111
|
+
- !ruby/object:Gem::Dependency
|
112
|
+
name: rubocop-fnando
|
113
|
+
requirement: !ruby/object:Gem::Requirement
|
114
|
+
requirements:
|
115
|
+
- - ">="
|
116
|
+
- !ruby/object:Gem::Version
|
117
|
+
version: '0'
|
118
|
+
type: :development
|
119
|
+
prerelease: false
|
120
|
+
version_requirements: !ruby/object:Gem::Requirement
|
121
|
+
requirements:
|
122
|
+
- - ">="
|
123
|
+
- !ruby/object:Gem::Version
|
124
|
+
version: '0'
|
83
125
|
- !ruby/object:Gem::Dependency
|
84
126
|
name: simplecov
|
85
127
|
requirement: !ruby/object:Gem::Requirement
|
@@ -102,6 +144,7 @@ executables: []
|
|
102
144
|
extensions: []
|
103
145
|
extra_rdoc_files: []
|
104
146
|
files:
|
147
|
+
- ".github/FUNDING.yml"
|
105
148
|
- ".gitignore"
|
106
149
|
- ".rubocop.yml"
|
107
150
|
- ".travis.yml"
|
@@ -127,14 +170,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
127
170
|
requirements:
|
128
171
|
- - ">="
|
129
172
|
- !ruby/object:Gem::Version
|
130
|
-
version:
|
173
|
+
version: 2.7.0
|
131
174
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
132
175
|
requirements:
|
133
176
|
- - ">="
|
134
177
|
- !ruby/object:Gem::Version
|
135
178
|
version: '0'
|
136
179
|
requirements: []
|
137
|
-
rubygems_version: 3.
|
180
|
+
rubygems_version: 3.2.22
|
138
181
|
signing_key:
|
139
182
|
specification_version: 4
|
140
183
|
summary: Access environment variables. Also includes presence validation, type coercion
|