nvar 0.1.2 → 0.3.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.github/workflows/rubyonrails-lint.yml +1 -1
- data/.tool-versions +1 -1
- data/Gemfile +3 -3
- data/Gemfile.lock +230 -144
- data/README.md +18 -5
- data/Rakefile +2 -2
- data/bin/standardrb +29 -0
- data/lib/nvar/engine.rb +3 -3
- data/lib/nvar/environment_variable.rb +9 -9
- data/lib/nvar/version.rb +1 -1
- data/lib/nvar.rb +27 -15
- data/nvar.gemspec +28 -29
- metadata +11 -24
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 50a7afaa683d712f4d58162159ac28c3830b58555fbf6b951024265ef3ca46c1
|
4
|
+
data.tar.gz: a61eda6ce582178c41953d12969449c106a82f6fa6a653d62f442e41de0547e2
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 1e1684de21ce2e210344d071901088eabe6a9063ce01930f2df37ae66248b71cc1680f00c512ba82844842e585d0d23b6e67b1c69452368fc26e5e20977aed27
|
7
|
+
data.tar.gz: 2a25adcffecc91d140912f3aef50d7fe6de776af814913935e24bc8351f1aa9bd7afa9bb582b34af9a53581d6d71e1510a9939233c22c8648fb919320fea68fa
|
data/.tool-versions
CHANGED
@@ -1 +1 @@
|
|
1
|
-
ruby
|
1
|
+
ruby 3.3.0
|
data/Gemfile
CHANGED
data/Gemfile.lock
CHANGED
@@ -1,194 +1,281 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
nvar (0.
|
4
|
+
nvar (0.3.0)
|
5
5
|
activesupport (>= 5.0.0, < 8.0)
|
6
6
|
|
7
7
|
GEM
|
8
8
|
remote: https://rubygems.org/
|
9
9
|
specs:
|
10
|
-
actioncable (
|
11
|
-
actionpack (=
|
12
|
-
activesupport (=
|
10
|
+
actioncable (7.1.3.2)
|
11
|
+
actionpack (= 7.1.3.2)
|
12
|
+
activesupport (= 7.1.3.2)
|
13
13
|
nio4r (~> 2.0)
|
14
14
|
websocket-driver (>= 0.6.1)
|
15
|
-
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
15
|
+
zeitwerk (~> 2.6)
|
16
|
+
actionmailbox (7.1.3.2)
|
17
|
+
actionpack (= 7.1.3.2)
|
18
|
+
activejob (= 7.1.3.2)
|
19
|
+
activerecord (= 7.1.3.2)
|
20
|
+
activestorage (= 7.1.3.2)
|
21
|
+
activesupport (= 7.1.3.2)
|
21
22
|
mail (>= 2.7.1)
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
23
|
+
net-imap
|
24
|
+
net-pop
|
25
|
+
net-smtp
|
26
|
+
actionmailer (7.1.3.2)
|
27
|
+
actionpack (= 7.1.3.2)
|
28
|
+
actionview (= 7.1.3.2)
|
29
|
+
activejob (= 7.1.3.2)
|
30
|
+
activesupport (= 7.1.3.2)
|
27
31
|
mail (~> 2.5, >= 2.5.4)
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
32
|
+
net-imap
|
33
|
+
net-pop
|
34
|
+
net-smtp
|
35
|
+
rails-dom-testing (~> 2.2)
|
36
|
+
actionpack (7.1.3.2)
|
37
|
+
actionview (= 7.1.3.2)
|
38
|
+
activesupport (= 7.1.3.2)
|
39
|
+
nokogiri (>= 1.8.5)
|
40
|
+
racc
|
41
|
+
rack (>= 2.2.4)
|
42
|
+
rack-session (>= 1.0.1)
|
33
43
|
rack-test (>= 0.6.3)
|
34
|
-
rails-dom-testing (~> 2.
|
35
|
-
rails-html-sanitizer (~> 1.
|
36
|
-
actiontext (
|
37
|
-
actionpack (=
|
38
|
-
activerecord (=
|
39
|
-
activestorage (=
|
40
|
-
activesupport (=
|
44
|
+
rails-dom-testing (~> 2.2)
|
45
|
+
rails-html-sanitizer (~> 1.6)
|
46
|
+
actiontext (7.1.3.2)
|
47
|
+
actionpack (= 7.1.3.2)
|
48
|
+
activerecord (= 7.1.3.2)
|
49
|
+
activestorage (= 7.1.3.2)
|
50
|
+
activesupport (= 7.1.3.2)
|
51
|
+
globalid (>= 0.6.0)
|
41
52
|
nokogiri (>= 1.8.5)
|
42
|
-
actionview (
|
43
|
-
activesupport (=
|
53
|
+
actionview (7.1.3.2)
|
54
|
+
activesupport (= 7.1.3.2)
|
44
55
|
builder (~> 3.1)
|
45
|
-
erubi (~> 1.
|
46
|
-
rails-dom-testing (~> 2.
|
47
|
-
rails-html-sanitizer (~> 1.
|
48
|
-
activejob (
|
49
|
-
activesupport (=
|
56
|
+
erubi (~> 1.11)
|
57
|
+
rails-dom-testing (~> 2.2)
|
58
|
+
rails-html-sanitizer (~> 1.6)
|
59
|
+
activejob (7.1.3.2)
|
60
|
+
activesupport (= 7.1.3.2)
|
50
61
|
globalid (>= 0.3.6)
|
51
|
-
activemodel (
|
52
|
-
activesupport (=
|
53
|
-
activerecord (
|
54
|
-
activemodel (=
|
55
|
-
activesupport (=
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
activesupport (
|
62
|
+
activemodel (7.1.3.2)
|
63
|
+
activesupport (= 7.1.3.2)
|
64
|
+
activerecord (7.1.3.2)
|
65
|
+
activemodel (= 7.1.3.2)
|
66
|
+
activesupport (= 7.1.3.2)
|
67
|
+
timeout (>= 0.4.0)
|
68
|
+
activestorage (7.1.3.2)
|
69
|
+
actionpack (= 7.1.3.2)
|
70
|
+
activejob (= 7.1.3.2)
|
71
|
+
activerecord (= 7.1.3.2)
|
72
|
+
activesupport (= 7.1.3.2)
|
73
|
+
marcel (~> 1.0)
|
74
|
+
activesupport (7.1.3.2)
|
75
|
+
base64
|
76
|
+
bigdecimal
|
64
77
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
78
|
+
connection_pool (>= 2.2.5)
|
79
|
+
drb
|
65
80
|
i18n (>= 1.6, < 2)
|
66
81
|
minitest (>= 5.1)
|
82
|
+
mutex_m
|
67
83
|
tzinfo (~> 2.0)
|
68
|
-
zeitwerk (~> 2.3)
|
69
84
|
ast (2.4.2)
|
85
|
+
base64 (0.2.0)
|
86
|
+
bigdecimal (3.1.6)
|
70
87
|
builder (3.2.4)
|
71
|
-
bundler-audit (0.9.
|
88
|
+
bundler-audit (0.9.1)
|
72
89
|
bundler (>= 1.2.0, < 3)
|
73
90
|
thor (~> 1.0)
|
74
91
|
byebug (11.1.3)
|
75
|
-
climate_control (1.0
|
76
|
-
concurrent-ruby (1.
|
92
|
+
climate_control (1.2.0)
|
93
|
+
concurrent-ruby (1.2.3)
|
94
|
+
connection_pool (2.4.1)
|
77
95
|
crass (1.0.6)
|
78
|
-
|
96
|
+
date (3.3.4)
|
97
|
+
diff-lcs (1.5.1)
|
79
98
|
docile (1.4.0)
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
99
|
+
drb (2.2.0)
|
100
|
+
ruby2_keywords
|
101
|
+
erubi (1.12.0)
|
102
|
+
globalid (1.2.1)
|
103
|
+
activesupport (>= 6.1)
|
104
|
+
i18n (1.14.1)
|
84
105
|
concurrent-ruby (~> 1.0)
|
85
|
-
|
106
|
+
io-console (0.7.2)
|
107
|
+
irb (1.11.2)
|
108
|
+
rdoc
|
109
|
+
reline (>= 0.4.2)
|
110
|
+
json (2.7.1)
|
111
|
+
language_server-protocol (3.17.0.3)
|
112
|
+
lint_roller (1.1.0)
|
113
|
+
loofah (2.22.0)
|
86
114
|
crass (~> 1.0.2)
|
87
|
-
nokogiri (>= 1.
|
88
|
-
mail (2.
|
115
|
+
nokogiri (>= 1.12.0)
|
116
|
+
mail (2.8.1)
|
89
117
|
mini_mime (>= 0.1.1)
|
118
|
+
net-imap
|
119
|
+
net-pop
|
120
|
+
net-smtp
|
90
121
|
marcel (1.0.2)
|
91
|
-
|
92
|
-
|
93
|
-
|
94
|
-
|
95
|
-
|
96
|
-
|
97
|
-
|
122
|
+
mini_mime (1.1.5)
|
123
|
+
minitest (5.22.2)
|
124
|
+
mutex_m (0.2.0)
|
125
|
+
net-imap (0.4.10)
|
126
|
+
date
|
127
|
+
net-protocol
|
128
|
+
net-pop (0.1.2)
|
129
|
+
net-protocol
|
130
|
+
net-protocol (0.2.2)
|
131
|
+
timeout
|
132
|
+
net-smtp (0.4.0.1)
|
133
|
+
net-protocol
|
134
|
+
nio4r (2.7.0)
|
135
|
+
nokogiri (1.16.2-aarch64-linux)
|
136
|
+
racc (~> 1.4)
|
137
|
+
nokogiri (1.16.2-arm-linux)
|
138
|
+
racc (~> 1.4)
|
139
|
+
nokogiri (1.16.2-arm64-darwin)
|
140
|
+
racc (~> 1.4)
|
141
|
+
nokogiri (1.16.2-x86-linux)
|
98
142
|
racc (~> 1.4)
|
99
|
-
|
100
|
-
|
143
|
+
nokogiri (1.16.2-x86_64-darwin)
|
144
|
+
racc (~> 1.4)
|
145
|
+
nokogiri (1.16.2-x86_64-linux)
|
146
|
+
racc (~> 1.4)
|
147
|
+
parallel (1.24.0)
|
148
|
+
parser (3.3.0.5)
|
101
149
|
ast (~> 2.4.1)
|
102
|
-
|
103
|
-
|
104
|
-
|
105
|
-
|
106
|
-
|
107
|
-
|
108
|
-
|
109
|
-
|
110
|
-
|
111
|
-
|
112
|
-
|
113
|
-
|
114
|
-
|
115
|
-
|
116
|
-
|
117
|
-
|
150
|
+
racc
|
151
|
+
prism (0.24.0)
|
152
|
+
psych (5.1.2)
|
153
|
+
stringio
|
154
|
+
racc (1.7.3)
|
155
|
+
rack (3.0.9.1)
|
156
|
+
rack-session (2.0.0)
|
157
|
+
rack (>= 3.0.0)
|
158
|
+
rack-test (2.1.0)
|
159
|
+
rack (>= 1.3)
|
160
|
+
rackup (2.1.0)
|
161
|
+
rack (>= 3)
|
162
|
+
webrick (~> 1.8)
|
163
|
+
rails (7.1.3.2)
|
164
|
+
actioncable (= 7.1.3.2)
|
165
|
+
actionmailbox (= 7.1.3.2)
|
166
|
+
actionmailer (= 7.1.3.2)
|
167
|
+
actionpack (= 7.1.3.2)
|
168
|
+
actiontext (= 7.1.3.2)
|
169
|
+
actionview (= 7.1.3.2)
|
170
|
+
activejob (= 7.1.3.2)
|
171
|
+
activemodel (= 7.1.3.2)
|
172
|
+
activerecord (= 7.1.3.2)
|
173
|
+
activestorage (= 7.1.3.2)
|
174
|
+
activesupport (= 7.1.3.2)
|
118
175
|
bundler (>= 1.15.0)
|
119
|
-
railties (=
|
120
|
-
|
121
|
-
|
122
|
-
|
176
|
+
railties (= 7.1.3.2)
|
177
|
+
rails-dom-testing (2.2.0)
|
178
|
+
activesupport (>= 5.0.0)
|
179
|
+
minitest
|
123
180
|
nokogiri (>= 1.6)
|
124
|
-
rails-html-sanitizer (1.
|
125
|
-
loofah (~> 2.
|
126
|
-
|
127
|
-
|
128
|
-
|
129
|
-
|
130
|
-
|
131
|
-
|
132
|
-
|
181
|
+
rails-html-sanitizer (1.6.0)
|
182
|
+
loofah (~> 2.21)
|
183
|
+
nokogiri (~> 1.14)
|
184
|
+
railties (7.1.3.2)
|
185
|
+
actionpack (= 7.1.3.2)
|
186
|
+
activesupport (= 7.1.3.2)
|
187
|
+
irb
|
188
|
+
rackup (>= 1.0.0)
|
189
|
+
rake (>= 12.2)
|
190
|
+
thor (~> 1.0, >= 1.2.2)
|
191
|
+
zeitwerk (~> 2.6)
|
192
|
+
rainbow (3.1.1)
|
133
193
|
rake (12.3.3)
|
134
|
-
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
rspec
|
141
|
-
rspec-
|
142
|
-
|
194
|
+
rdoc (6.6.2)
|
195
|
+
psych (>= 4.0.0)
|
196
|
+
regexp_parser (2.9.0)
|
197
|
+
reline (0.4.3)
|
198
|
+
io-console (~> 0.5)
|
199
|
+
rexml (3.2.6)
|
200
|
+
rspec (3.13.0)
|
201
|
+
rspec-core (~> 3.13.0)
|
202
|
+
rspec-expectations (~> 3.13.0)
|
203
|
+
rspec-mocks (~> 3.13.0)
|
204
|
+
rspec-core (3.13.0)
|
205
|
+
rspec-support (~> 3.13.0)
|
206
|
+
rspec-expectations (3.13.0)
|
143
207
|
diff-lcs (>= 1.2.0, < 2.0)
|
144
|
-
rspec-support (~> 3.
|
145
|
-
rspec-mocks (3.
|
208
|
+
rspec-support (~> 3.13.0)
|
209
|
+
rspec-mocks (3.13.0)
|
146
210
|
diff-lcs (>= 1.2.0, < 2.0)
|
147
|
-
rspec-support (~> 3.
|
148
|
-
rspec-support (3.
|
149
|
-
rubocop (1.
|
211
|
+
rspec-support (~> 3.13.0)
|
212
|
+
rspec-support (3.13.1)
|
213
|
+
rubocop (1.60.2)
|
214
|
+
json (~> 2.3)
|
215
|
+
language_server-protocol (>= 3.17.0)
|
150
216
|
parallel (~> 1.10)
|
151
|
-
parser (>= 3.
|
217
|
+
parser (>= 3.3.0.2)
|
152
218
|
rainbow (>= 2.2.2, < 4.0)
|
153
219
|
regexp_parser (>= 1.8, < 3.0)
|
154
|
-
rexml
|
155
|
-
rubocop-ast (>= 1.
|
220
|
+
rexml (>= 3.2.5, < 4.0)
|
221
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
156
222
|
ruby-progressbar (~> 1.7)
|
157
|
-
unicode-display_width (>=
|
158
|
-
rubocop-ast (1.
|
159
|
-
parser (>= 3.
|
160
|
-
rubocop-
|
161
|
-
rubocop (
|
162
|
-
|
163
|
-
|
164
|
-
|
165
|
-
|
166
|
-
|
223
|
+
unicode-display_width (>= 2.4.0, < 3.0)
|
224
|
+
rubocop-ast (1.30.0)
|
225
|
+
parser (>= 3.2.1.0)
|
226
|
+
rubocop-performance (1.20.2)
|
227
|
+
rubocop (>= 1.48.1, < 2.0)
|
228
|
+
rubocop-ast (>= 1.30.0, < 2.0)
|
229
|
+
ruby-lsp (0.14.3)
|
230
|
+
language_server-protocol (~> 3.17.0)
|
231
|
+
prism (>= 0.22.0, < 0.25)
|
232
|
+
sorbet-runtime (>= 0.5.10782)
|
233
|
+
ruby-lsp-rspec (0.1.10)
|
234
|
+
ruby-lsp (~> 0.14.0)
|
235
|
+
ruby-progressbar (1.13.0)
|
236
|
+
ruby2_keywords (0.0.5)
|
237
|
+
simplecov (0.22.0)
|
167
238
|
docile (~> 1.1)
|
168
239
|
simplecov-html (~> 0.11)
|
169
240
|
simplecov_json_formatter (~> 0.1)
|
170
241
|
simplecov-html (0.12.3)
|
171
|
-
simplecov_json_formatter (0.1.
|
172
|
-
|
173
|
-
|
174
|
-
|
175
|
-
|
176
|
-
|
177
|
-
|
178
|
-
|
179
|
-
|
180
|
-
|
181
|
-
|
242
|
+
simplecov_json_formatter (0.1.4)
|
243
|
+
sorbet-runtime (0.5.11276)
|
244
|
+
standard (1.34.0)
|
245
|
+
language_server-protocol (~> 3.17.0.2)
|
246
|
+
lint_roller (~> 1.0)
|
247
|
+
rubocop (~> 1.60)
|
248
|
+
standard-custom (~> 1.0.0)
|
249
|
+
standard-performance (~> 1.3)
|
250
|
+
standard-custom (1.0.2)
|
251
|
+
lint_roller (~> 1.0)
|
252
|
+
rubocop (~> 1.50)
|
253
|
+
standard-performance (1.3.1)
|
254
|
+
lint_roller (~> 1.1)
|
255
|
+
rubocop-performance (~> 1.20.2)
|
256
|
+
standardrb (1.0.1)
|
257
|
+
standard
|
258
|
+
stringio (3.1.0)
|
259
|
+
tempfile (0.2.1)
|
260
|
+
thor (1.3.1)
|
261
|
+
timeout (0.4.1)
|
262
|
+
tzinfo (2.0.6)
|
182
263
|
concurrent-ruby (~> 1.0)
|
183
|
-
unicode-display_width (2.
|
184
|
-
vcr (6.
|
185
|
-
|
264
|
+
unicode-display_width (2.5.0)
|
265
|
+
vcr (6.2.0)
|
266
|
+
webrick (1.8.1)
|
267
|
+
websocket-driver (0.7.6)
|
186
268
|
websocket-extensions (>= 0.1.0)
|
187
269
|
websocket-extensions (0.1.5)
|
188
|
-
zeitwerk (2.
|
270
|
+
zeitwerk (2.6.13)
|
189
271
|
|
190
272
|
PLATFORMS
|
191
|
-
|
273
|
+
aarch64-linux
|
274
|
+
arm-linux
|
275
|
+
arm64-darwin
|
276
|
+
x86-linux
|
277
|
+
x86_64-darwin
|
278
|
+
x86_64-linux
|
192
279
|
|
193
280
|
DEPENDENCIES
|
194
281
|
bundler-audit
|
@@ -198,12 +285,11 @@ DEPENDENCIES
|
|
198
285
|
rails
|
199
286
|
rake (~> 12.0)
|
200
287
|
rspec (~> 3.0)
|
201
|
-
|
202
|
-
rubocop-rake
|
203
|
-
rubocop-rspec
|
288
|
+
ruby-lsp-rspec
|
204
289
|
simplecov
|
290
|
+
standardrb
|
205
291
|
tempfile
|
206
292
|
vcr
|
207
293
|
|
208
294
|
BUNDLED WITH
|
209
|
-
2.
|
295
|
+
2.5.6
|
data/README.md
CHANGED
@@ -5,7 +5,17 @@ If your app relies on lots of environment secrets, onboarding's tough. New team
|
|
5
5
|
You can use `Nvar` in Ruby apps, with out-of-the-box support provided for Rails.
|
6
6
|
## Installation
|
7
7
|
|
8
|
-
Add the gem to your Gemfile and install it with `bundle add nvar`. If you're not on Rails, you'll need to make sure that `Nvar` is required with `require 'nvar'`, and then manually call `Nvar
|
8
|
+
Add the gem to your Gemfile and install it with `bundle add nvar`. If you're not on Rails, you'll need to make sure that `Nvar` is required with `require 'nvar'`, and then manually call `Nvar.load_all` as early as is appropriate.
|
9
|
+
|
10
|
+
It's recommended to do this by adding the following to `config/application.rb`:
|
11
|
+
|
12
|
+
```rb
|
13
|
+
require "dotenv/load" # if using in tandem with dotenv
|
14
|
+
require "nvar"
|
15
|
+
|
16
|
+
Nvar.load_all
|
17
|
+
```
|
18
|
+
|
9
19
|
## Configuration
|
10
20
|
|
11
21
|
`Nvar` is configured by way of `config/environment_variables.yml`. If you're on Rails, this file will be created for you automatically. Each key corresponds to the name of a required environment variable, and houses its configuration, all of which is optional.
|
@@ -36,7 +46,7 @@ This is just a glimpse of `Nvar`'s greater aim - centralizing configuration for
|
|
36
46
|
|
37
47
|
### Passthrough
|
38
48
|
|
39
|
-
The final config option, `passthrough`, deserves some extra detail. By default, `Nvar` sets your environment constants to their actual values in development and production environments, and to their names in test environments.
|
49
|
+
The final config option, `passthrough`, deserves some extra detail. By default, `Nvar` sets your environment constants to their actual values in development and production environments, and to their names in test environments, in order to prevent your tests from depending on their values.
|
40
50
|
|
41
51
|
In production/development, or in test with passthrough active:
|
42
52
|
|
@@ -52,17 +62,20 @@ irb(main):001:0> REQUIRED_ENV_VAR
|
|
52
62
|
=> "REQUIRED_ENV_VAR"
|
53
63
|
```
|
54
64
|
|
55
|
-
Your tests shouldn't be reliant on your environment, so
|
65
|
+
Your tests shouldn't be reliant on your environment, so setting `passthrough` to `true` in `config/environment_variables.yml` isn't recommended. Passthrough is, however, useful for recording VCR cassettes. Set NVAR_PASSTHROUGH to a comma-separated list of environment variable names while running your tests, then unset it and run your tests again to make sure they're not reliant on your environment. For example:
|
56
66
|
|
67
|
+
```
|
68
|
+
NVAR_PASSTHROUGH=GITHUB_APP_PRIVATE_KEY,GITHUB_APP_INSTALLATION_ID bundle exec rspec
|
69
|
+
```
|
57
70
|
|
58
71
|
## Usage
|
59
72
|
|
60
73
|
Now that you've been through and configured the environment variables that are necessary for your app, `Nvar` will write your environment variables to top-level constants, cast to any types you've specified, and raise an informative error if any are absent.
|
61
74
|
### .env files
|
62
75
|
|
63
|
-
`Nvar` works well with gems like `dotenv
|
76
|
+
`Nvar` works well with gems like `dotenv` that source their config from a `.env` file. If an environment variable is unset when the app initializes and isn't present in `.env`, it will be added to that file. If a default value is specified in your `Nvar` config, that will be passed to `.env` too.
|
64
77
|
|
65
|
-
When using gems such as `dotenv
|
78
|
+
When using gems such as `dotenv`, make sure you load those first so that the environment is ready for `Nvar` to check.
|
66
79
|
|
67
80
|
### `rake nvar:verify_environment_file`
|
68
81
|
|
data/Rakefile
CHANGED
data/bin/standardrb
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
# frozen_string_literal: true
|
3
|
+
|
4
|
+
#
|
5
|
+
# This file was generated by Bundler.
|
6
|
+
#
|
7
|
+
# The application 'standardrb' is installed as part of a gem, and
|
8
|
+
# this file is here to facilitate running it.
|
9
|
+
#
|
10
|
+
|
11
|
+
require "pathname"
|
12
|
+
ENV["BUNDLE_GEMFILE"] ||= File.expand_path("../../Gemfile",
|
13
|
+
Pathname.new(__FILE__).realpath)
|
14
|
+
|
15
|
+
bundle_binstub = File.expand_path("../bundle", __FILE__)
|
16
|
+
|
17
|
+
if File.file?(bundle_binstub)
|
18
|
+
if File.read(bundle_binstub, 300) =~ /This file was generated by Bundler/
|
19
|
+
load(bundle_binstub)
|
20
|
+
else
|
21
|
+
abort("Your `bin/bundle` was not generated by Bundler, so this binstub cannot run.
|
22
|
+
Replace `bin/bundle` by running `bundle binstubs bundler --force`, then run this command again.")
|
23
|
+
end
|
24
|
+
end
|
25
|
+
|
26
|
+
require "rubygems"
|
27
|
+
require "bundler/setup"
|
28
|
+
|
29
|
+
load Gem.bin_path("standard", "standardrb")
|
data/lib/nvar/engine.rb
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require_relative
|
3
|
+
require "rails"
|
4
|
+
require_relative "environment_variable"
|
5
5
|
|
6
6
|
module Nvar
|
7
7
|
class Engine < Rails::Engine # :nodoc:
|
@@ -21,7 +21,7 @@ module Nvar
|
|
21
21
|
end
|
22
22
|
|
23
23
|
rake_tasks do
|
24
|
-
load
|
24
|
+
load "nvar/rails/tasks/verify_environment_file.rake"
|
25
25
|
end
|
26
26
|
end
|
27
27
|
end
|
@@ -2,21 +2,21 @@
|
|
2
2
|
|
3
3
|
# Wrapper for retrieval of environment variables. See
|
4
4
|
# config/initializers/environment_variable_loader.rb to check out how it's used.
|
5
|
-
require
|
6
|
-
require
|
7
|
-
require
|
5
|
+
require "active_support/core_ext/hash/keys"
|
6
|
+
require "active_support/core_ext/object/blank"
|
7
|
+
require "yaml"
|
8
8
|
|
9
9
|
module Nvar
|
10
10
|
# Wrapper for loading environment variables, used across relevant Rake tasks
|
11
11
|
class EnvironmentVariable
|
12
12
|
attr_reader :name, :type, :value, :required, :defined
|
13
13
|
|
14
|
-
def initialize(name:, type:
|
14
|
+
def initialize(name:, type: "String", filter_from_requests: nil, **args)
|
15
15
|
@name = name
|
16
16
|
@type = type
|
17
17
|
@required = args[:required].nil? ? true : args[:required]
|
18
18
|
@filter_from_requests = filter_from_requests.yield_self { |f| [true, false].include?(f) ? f : f&.to_sym }
|
19
|
-
@value = fetch_value(**args.slice(:passthrough, :default_value))
|
19
|
+
@value = fetch_value(**args.slice(:passthrough, :default_value).with_defaults(passthrough: ENV.fetch("NVAR_PASSTHROUGH", "").split(",").include?(name.to_s)))
|
20
20
|
@defined = true
|
21
21
|
rescue KeyError
|
22
22
|
@value = args[:default_value]
|
@@ -26,7 +26,7 @@ module Nvar
|
|
26
26
|
def to_const
|
27
27
|
raise Nvar::EnvironmentVariableNotPresentError, self unless defined
|
28
28
|
|
29
|
-
Object.const_set(name, typecast_value)
|
29
|
+
Object.const_set(name, typecast_value) unless Object.const_defined?(name)
|
30
30
|
end
|
31
31
|
|
32
32
|
def set?
|
@@ -40,7 +40,7 @@ module Nvar
|
|
40
40
|
def add_to_env_file
|
41
41
|
return if present_in_env_file?
|
42
42
|
|
43
|
-
File.write(Nvar.env_file_path, to_env_assign, mode:
|
43
|
+
File.write(Nvar.env_file_path, to_env_assign, mode: "a")
|
44
44
|
end
|
45
45
|
|
46
46
|
def filter_from_vcr_cassettes(config)
|
@@ -50,7 +50,7 @@ module Nvar
|
|
50
50
|
# :nocov:
|
51
51
|
case @filter_from_requests
|
52
52
|
when :alone_as_basic_auth_password
|
53
|
-
Base64.encode64([
|
53
|
+
Base64.encode64(["", @value].join(":")).delete("\n")
|
54
54
|
when true
|
55
55
|
@value
|
56
56
|
end
|
@@ -76,7 +76,7 @@ module Nvar
|
|
76
76
|
end
|
77
77
|
|
78
78
|
def fetch_value(passthrough: false, default_value: nil)
|
79
|
-
return
|
79
|
+
return default_value || name.to_s if Nvar.env.test? && !passthrough
|
80
80
|
|
81
81
|
required ? ENV.fetch(name.to_s) : ENV[name.to_s]
|
82
82
|
end
|
data/lib/nvar/version.rb
CHANGED
data/lib/nvar.rb
CHANGED
@@ -1,18 +1,21 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require
|
4
|
-
require
|
5
|
-
require
|
6
|
-
require
|
3
|
+
require "nvar/version"
|
4
|
+
require "nvar/environment_variable"
|
5
|
+
require "nvar/engine" if defined?(Rails)
|
6
|
+
require "active_support/core_ext/module/attribute_accessors"
|
7
|
+
require "active_support/core_ext/hash/reverse_merge"
|
8
|
+
require "active_support/string_inquirer"
|
7
9
|
|
8
10
|
# Centralized configuration for required environment variables in your Ruby app.
|
9
11
|
module Nvar
|
10
|
-
mattr_accessor :config_file_path, default: File.expand_path(
|
11
|
-
mattr_accessor :env_file_path, default: File.expand_path(
|
12
|
+
mattr_accessor :config_file_path, default: File.expand_path("config/environment_variables.yml")
|
13
|
+
mattr_accessor :env_file_path, default: File.expand_path(".env")
|
14
|
+
mattr_accessor :env
|
12
15
|
|
13
16
|
# Comments in .env files must have a leading '#' symbol. This cannot be
|
14
17
|
# followed by a space.
|
15
|
-
ENV_COMMENT = <<~
|
18
|
+
ENV_COMMENT = <<~COMMENT
|
16
19
|
#Environment variables are managed through this file (.env). The Scripts to
|
17
20
|
#Rule Them All (in script/) load the environment from here, and the app warns
|
18
21
|
#on startup if any required environment variables are missing. You can see the
|
@@ -33,17 +36,26 @@ module Nvar
|
|
33
36
|
end
|
34
37
|
|
35
38
|
def message
|
36
|
-
"The following variables are unset or blank: #{vars.map(&:name).join(
|
39
|
+
"The following variables are unset or blank: #{vars.map(&:name).join(", ")}"
|
37
40
|
end
|
38
41
|
end
|
39
42
|
|
40
43
|
class << self
|
44
|
+
def env
|
45
|
+
if defined?(Rails)
|
46
|
+
Rails.env
|
47
|
+
else
|
48
|
+
ActiveSupport::StringInquirer.new(@@env&.to_s || ENV["RAILS_ENV"] || ENV["RACK_ENV"] || "development")
|
49
|
+
end
|
50
|
+
end
|
51
|
+
|
41
52
|
def configure_for_rails(app)
|
42
|
-
self.config_file_path = app.root.join(
|
43
|
-
self.env_file_path = app.root.join(
|
53
|
+
self.config_file_path = app.root.join("config/environment_variables.yml")
|
54
|
+
self.env_file_path = app.root.join(".env")
|
44
55
|
[config_file_path, env_file_path].each do |path|
|
45
|
-
File.open(path,
|
56
|
+
File.open(path, "w") {} unless path.exist? # rubocop:disable Lint/EmptyBlock
|
46
57
|
end
|
58
|
+
self.env = Rails.env
|
47
59
|
end
|
48
60
|
|
49
61
|
def load_all
|
@@ -67,14 +79,14 @@ module Nvar
|
|
67
79
|
end
|
68
80
|
|
69
81
|
def touch_env
|
70
|
-
File.write(env_file_path, ENV_COMMENT, mode:
|
82
|
+
File.write(env_file_path, ENV_COMMENT, mode: "w") unless File.exist?(env_file_path)
|
71
83
|
end
|
72
84
|
|
73
85
|
def verify_env(write_to_file: true)
|
74
86
|
_set, unset = all
|
75
87
|
return true if all_required_env_variables_set?
|
76
88
|
|
77
|
-
puts
|
89
|
+
puts "Please update .env with values for each environment variable:"
|
78
90
|
touch_env if write_to_file
|
79
91
|
unset.each do |variable|
|
80
92
|
variable.add_to_env_file if write_to_file
|
@@ -88,11 +100,11 @@ module Nvar
|
|
88
100
|
private
|
89
101
|
|
90
102
|
def all_required_env_variables_set?
|
91
|
-
all[1].none? || ENV[
|
103
|
+
all[1].none? || ENV["RAILS_ENV"] == "test"
|
92
104
|
end
|
93
105
|
|
94
106
|
def variables
|
95
|
-
(YAML.
|
107
|
+
(YAML.safe_load_file(config_file_path) || {}).deep_symbolize_keys
|
96
108
|
end
|
97
109
|
end
|
98
110
|
end
|
data/nvar.gemspec
CHANGED
@@ -1,45 +1,44 @@
|
|
1
1
|
# frozen_string_literal: true
|
2
2
|
|
3
|
-
require_relative
|
3
|
+
require_relative "lib/nvar/version"
|
4
4
|
|
5
5
|
Gem::Specification.new do |spec|
|
6
|
-
spec.name
|
7
|
-
spec.version
|
8
|
-
spec.authors
|
9
|
-
spec.email
|
6
|
+
spec.name = "nvar"
|
7
|
+
spec.version = Nvar::VERSION
|
8
|
+
spec.authors = ["Simon Fish"]
|
9
|
+
spec.email = ["si@mon.fish"]
|
10
10
|
|
11
|
-
spec.summary
|
12
|
-
spec.description
|
13
|
-
spec.homepage
|
14
|
-
spec.license
|
15
|
-
spec.required_ruby_version = Gem::Requirement.new(
|
11
|
+
spec.summary = "Manage environment variables in Ruby"
|
12
|
+
spec.description = "Manage environment variables in Ruby"
|
13
|
+
spec.homepage = "https://github.com/boardfish/nvar"
|
14
|
+
spec.license = "MIT"
|
15
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 3")
|
16
16
|
|
17
|
-
spec.metadata[
|
17
|
+
spec.metadata["allowed_push_host"] = "TODO: Set to 'http://mygemserver.com'"
|
18
18
|
|
19
|
-
spec.metadata[
|
20
|
-
spec.metadata[
|
21
|
-
spec.metadata[
|
19
|
+
spec.metadata["homepage_uri"] = spec.homepage
|
20
|
+
spec.metadata["source_code_uri"] = spec.homepage
|
21
|
+
spec.metadata["changelog_uri"] = spec.homepage
|
22
22
|
|
23
23
|
# Specify which files should be added to the gem when it is released.
|
24
24
|
# The `git ls-files -z` loads the files in the RubyGem that have been added into git.
|
25
25
|
spec.files = Dir.chdir(File.expand_path(__dir__)) do
|
26
26
|
`git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
27
27
|
end
|
28
|
-
spec.bindir
|
29
|
-
spec.executables
|
30
|
-
spec.require_paths = [
|
31
|
-
spec.add_runtime_dependency
|
32
|
-
spec.add_development_dependency
|
33
|
-
spec.add_development_dependency
|
34
|
-
spec.add_development_dependency
|
35
|
-
spec.add_development_dependency
|
36
|
-
spec.add_development_dependency
|
37
|
-
spec.add_development_dependency
|
38
|
-
spec.add_development_dependency
|
39
|
-
spec.add_development_dependency
|
40
|
-
spec.add_development_dependency
|
41
|
-
spec.add_development_dependency 'vcr'
|
28
|
+
spec.bindir = "exe"
|
29
|
+
spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
|
30
|
+
spec.require_paths = ["lib"]
|
31
|
+
spec.add_runtime_dependency "activesupport", [">= 5.0.0", "< 8.0"]
|
32
|
+
spec.add_development_dependency "bundler-audit"
|
33
|
+
spec.add_development_dependency "byebug"
|
34
|
+
spec.add_development_dependency "climate_control"
|
35
|
+
spec.add_development_dependency "rails"
|
36
|
+
spec.add_development_dependency "ruby-lsp-rspec"
|
37
|
+
spec.add_development_dependency "simplecov"
|
38
|
+
spec.add_development_dependency "standardrb"
|
39
|
+
spec.add_development_dependency "tempfile"
|
40
|
+
spec.add_development_dependency "vcr"
|
42
41
|
spec.metadata = {
|
43
|
-
|
42
|
+
"rubygems_mfa_required" => "true"
|
44
43
|
}
|
45
44
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: nvar
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.3.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Simon Fish
|
8
|
-
autorequire:
|
8
|
+
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-03-22 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|
@@ -87,21 +87,7 @@ dependencies:
|
|
87
87
|
- !ruby/object:Gem::Version
|
88
88
|
version: '0'
|
89
89
|
- !ruby/object:Gem::Dependency
|
90
|
-
name:
|
91
|
-
requirement: !ruby/object:Gem::Requirement
|
92
|
-
requirements:
|
93
|
-
- - "~>"
|
94
|
-
- !ruby/object:Gem::Version
|
95
|
-
version: 1.12.0
|
96
|
-
type: :development
|
97
|
-
prerelease: false
|
98
|
-
version_requirements: !ruby/object:Gem::Requirement
|
99
|
-
requirements:
|
100
|
-
- - "~>"
|
101
|
-
- !ruby/object:Gem::Version
|
102
|
-
version: 1.12.0
|
103
|
-
- !ruby/object:Gem::Dependency
|
104
|
-
name: rubocop-rake
|
90
|
+
name: ruby-lsp-rspec
|
105
91
|
requirement: !ruby/object:Gem::Requirement
|
106
92
|
requirements:
|
107
93
|
- - ">="
|
@@ -115,7 +101,7 @@ dependencies:
|
|
115
101
|
- !ruby/object:Gem::Version
|
116
102
|
version: '0'
|
117
103
|
- !ruby/object:Gem::Dependency
|
118
|
-
name:
|
104
|
+
name: simplecov
|
119
105
|
requirement: !ruby/object:Gem::Requirement
|
120
106
|
requirements:
|
121
107
|
- - ">="
|
@@ -129,7 +115,7 @@ dependencies:
|
|
129
115
|
- !ruby/object:Gem::Version
|
130
116
|
version: '0'
|
131
117
|
- !ruby/object:Gem::Dependency
|
132
|
-
name:
|
118
|
+
name: standardrb
|
133
119
|
requirement: !ruby/object:Gem::Requirement
|
134
120
|
requirements:
|
135
121
|
- - ">="
|
@@ -203,6 +189,7 @@ files:
|
|
203
189
|
- bin/rspec
|
204
190
|
- bin/rubocop
|
205
191
|
- bin/setup
|
192
|
+
- bin/standardrb
|
206
193
|
- lib/nvar.rb
|
207
194
|
- lib/nvar/engine.rb
|
208
195
|
- lib/nvar/environment_variable.rb
|
@@ -215,7 +202,7 @@ licenses:
|
|
215
202
|
- MIT
|
216
203
|
metadata:
|
217
204
|
rubygems_mfa_required: 'true'
|
218
|
-
post_install_message:
|
205
|
+
post_install_message:
|
219
206
|
rdoc_options: []
|
220
207
|
require_paths:
|
221
208
|
- lib
|
@@ -223,15 +210,15 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
223
210
|
requirements:
|
224
211
|
- - ">="
|
225
212
|
- !ruby/object:Gem::Version
|
226
|
-
version:
|
213
|
+
version: '3'
|
227
214
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
228
215
|
requirements:
|
229
216
|
- - ">="
|
230
217
|
- !ruby/object:Gem::Version
|
231
218
|
version: '0'
|
232
219
|
requirements: []
|
233
|
-
rubygems_version: 3.
|
234
|
-
signing_key:
|
220
|
+
rubygems_version: 3.5.6
|
221
|
+
signing_key:
|
235
222
|
specification_version: 4
|
236
223
|
summary: Manage environment variables in Ruby
|
237
224
|
test_files: []
|