superconfig 2.1.1 → 2.2.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- checksums.yaml +4 -4
- data/.github/workflows/ruby-tests.yml +3 -3
- data/.rubocop.yml +1 -1
- data/CHANGELOG.md +8 -0
- data/README.md +8 -0
- data/lib/superconfig.rb +52 -38
- data/superconfig.gemspec +2 -2
- metadata +4 -7
checksums.yaml
CHANGED
|
@@ -1,7 +1,7 @@
|
|
|
1
1
|
---
|
|
2
2
|
SHA256:
|
|
3
|
-
metadata.gz:
|
|
4
|
-
data.tar.gz:
|
|
3
|
+
metadata.gz: c4cefd39e531ddd3bd73508b42f10594c5723d57b3c78655b64a4a745c41be90
|
|
4
|
+
data.tar.gz: f115b83ecf9165eccadb65658f486274988f8741b7dc1031d80894d492194a35
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: c84799398211996ea64120c5d3d41cfb800cc17f4555719e3c7b6e857f6ed4b4b97dd28b067a982d6686c679888c77267da61d252913033a1e85848ab42f5cfd
|
|
7
|
+
data.tar.gz: ae6415b1f50f06eb63cdcf393486ecf2ccbaf23ab05663ba3641a3e4a0e242a2871b0ade58c1602e759c60a0506418cb8dd16536c9049098b3ba7ddf39be82de
|
|
@@ -19,14 +19,14 @@ jobs:
|
|
|
19
19
|
strategy:
|
|
20
20
|
fail-fast: false
|
|
21
21
|
matrix:
|
|
22
|
-
ruby: ["
|
|
22
|
+
ruby: ["3.1", "3.2", "3.3"]
|
|
23
23
|
gemfile:
|
|
24
24
|
- Gemfile
|
|
25
25
|
|
|
26
26
|
steps:
|
|
27
|
-
- uses: actions/checkout@
|
|
27
|
+
- uses: actions/checkout@v4
|
|
28
28
|
|
|
29
|
-
- uses: actions/cache@
|
|
29
|
+
- uses: actions/cache@v4
|
|
30
30
|
with:
|
|
31
31
|
path: vendor/bundle
|
|
32
32
|
key: >
|
data/.rubocop.yml
CHANGED
data/CHANGELOG.md
CHANGED
|
@@ -11,6 +11,14 @@ Prefix your message with one of the following:
|
|
|
11
11
|
- [Security] in case of vulnerabilities.
|
|
12
12
|
-->
|
|
13
13
|
|
|
14
|
+
# v2.2.1
|
|
15
|
+
|
|
16
|
+
- [Changed] Silence warnings when reassigning a method with `set`.
|
|
17
|
+
|
|
18
|
+
# v2.2.0
|
|
19
|
+
|
|
20
|
+
- [Added] `SuperConfig#set(key, value)` method to set arbitrary values.
|
|
21
|
+
|
|
14
22
|
## v2.1.1
|
|
15
23
|
|
|
16
24
|
- [Changed] Ensure bad JSON strings doesn't leak it's contents.
|
data/README.md
CHANGED
|
@@ -73,6 +73,14 @@ Config = SuperConfig.new do
|
|
|
73
73
|
end
|
|
74
74
|
```
|
|
75
75
|
|
|
76
|
+
You can also set values using `SuperConfig#set`.
|
|
77
|
+
|
|
78
|
+
```ruby
|
|
79
|
+
Config = SuperConfig.new do
|
|
80
|
+
set :domain, "example.com"
|
|
81
|
+
end
|
|
82
|
+
```
|
|
83
|
+
|
|
76
84
|
You may want to start a debug session without raising exceptions for missing
|
|
77
85
|
variables. In this case, just pass `raise_exception: false` instead to log error
|
|
78
86
|
messages to `$stderr`. This is especially great with Rails' credentials command
|
data/lib/superconfig.rb
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
3
|
module SuperConfig
|
|
4
|
-
VERSION = "2.
|
|
4
|
+
VERSION = "2.2.1"
|
|
5
5
|
|
|
6
6
|
MissingEnvironmentVariable = Class.new(StandardError)
|
|
7
7
|
MissingCallable = Class.new(StandardError)
|
|
8
8
|
|
|
9
|
-
def self.new(
|
|
10
|
-
Base.new(
|
|
9
|
+
def self.new(...)
|
|
10
|
+
Base.new(...)
|
|
11
11
|
end
|
|
12
12
|
|
|
13
13
|
class Base
|
|
@@ -28,34 +28,6 @@ module SuperConfig
|
|
|
28
28
|
end
|
|
29
29
|
alias inspect to_s
|
|
30
30
|
|
|
31
|
-
def set(
|
|
32
|
-
name,
|
|
33
|
-
type,
|
|
34
|
-
default = nil,
|
|
35
|
-
required: false,
|
|
36
|
-
aliases: [],
|
|
37
|
-
description: nil
|
|
38
|
-
)
|
|
39
|
-
name = name.to_s
|
|
40
|
-
env_var = name.upcase
|
|
41
|
-
|
|
42
|
-
@attributes[env_var] = {required: required, default: default}
|
|
43
|
-
|
|
44
|
-
name = "#{name}?" if type == bool
|
|
45
|
-
|
|
46
|
-
validate!(env_var, required, description)
|
|
47
|
-
|
|
48
|
-
define_singleton_method(name) do
|
|
49
|
-
return default unless @env.key?(env_var)
|
|
50
|
-
|
|
51
|
-
coerce(env_var, type, @env[env_var])
|
|
52
|
-
end
|
|
53
|
-
|
|
54
|
-
aliases.each do |alias_name|
|
|
55
|
-
define_singleton_method(alias_name, method(name))
|
|
56
|
-
end
|
|
57
|
-
end
|
|
58
|
-
|
|
59
31
|
def validate!(env_var, required, description)
|
|
60
32
|
return unless required
|
|
61
33
|
return if @env.key?(env_var)
|
|
@@ -72,21 +44,27 @@ module SuperConfig
|
|
|
72
44
|
end
|
|
73
45
|
|
|
74
46
|
def mandatory(name, type, aliases: [], description: nil)
|
|
75
|
-
|
|
47
|
+
assign(
|
|
76
48
|
name,
|
|
77
49
|
type,
|
|
78
50
|
required: true,
|
|
79
|
-
aliases
|
|
80
|
-
description:
|
|
51
|
+
aliases:,
|
|
52
|
+
description:
|
|
81
53
|
)
|
|
82
54
|
end
|
|
83
55
|
|
|
84
56
|
def optional(name, type, default = nil, aliases: [], description: nil)
|
|
85
|
-
|
|
57
|
+
assign(name, type, default, aliases:, description:)
|
|
58
|
+
end
|
|
59
|
+
|
|
60
|
+
def set(name, value)
|
|
61
|
+
silence_warnings do
|
|
62
|
+
property(name) { value }
|
|
63
|
+
end
|
|
86
64
|
end
|
|
87
65
|
|
|
88
66
|
def property(name, func = nil, cache: true, description: nil, &block) # rubocop:disable Lint/UnusedMethodArgument
|
|
89
|
-
callable =
|
|
67
|
+
callable = func || block
|
|
90
68
|
|
|
91
69
|
unless callable
|
|
92
70
|
raise MissingCallable, "arg[1] must respond to #call or pass a block"
|
|
@@ -103,7 +81,7 @@ module SuperConfig
|
|
|
103
81
|
|
|
104
82
|
def credential(name, &block)
|
|
105
83
|
define_singleton_method(name) do
|
|
106
|
-
@__cache__["_credential_#{name}"
|
|
84
|
+
@__cache__[:"_credential_#{name}"] ||= begin
|
|
107
85
|
value = Rails.application.credentials.fetch(name)
|
|
108
86
|
block ? block.call(value) : value # rubocop:disable Performance/RedundantBlockCall
|
|
109
87
|
end
|
|
@@ -208,7 +186,43 @@ module SuperConfig
|
|
|
208
186
|
args = [name, value]
|
|
209
187
|
args << sub_type if sub_type
|
|
210
188
|
|
|
211
|
-
send("coerce_to_#{main_type}", *args)
|
|
189
|
+
send(:"coerce_to_#{main_type}", *args)
|
|
190
|
+
end
|
|
191
|
+
|
|
192
|
+
private def assign(
|
|
193
|
+
name,
|
|
194
|
+
type,
|
|
195
|
+
default = nil,
|
|
196
|
+
required: false,
|
|
197
|
+
aliases: [],
|
|
198
|
+
description: nil
|
|
199
|
+
)
|
|
200
|
+
name = name.to_s
|
|
201
|
+
env_var = name.upcase
|
|
202
|
+
|
|
203
|
+
@attributes[env_var] = {required:, default:}
|
|
204
|
+
|
|
205
|
+
name = "#{name}?" if type == bool
|
|
206
|
+
|
|
207
|
+
validate!(env_var, required, description)
|
|
208
|
+
|
|
209
|
+
define_singleton_method(name) do
|
|
210
|
+
return default unless @env.key?(env_var)
|
|
211
|
+
|
|
212
|
+
coerce(env_var, type, @env[env_var])
|
|
213
|
+
end
|
|
214
|
+
|
|
215
|
+
aliases.each do |alias_name|
|
|
216
|
+
define_singleton_method(alias_name, method(name))
|
|
217
|
+
end
|
|
218
|
+
end
|
|
219
|
+
|
|
220
|
+
private def silence_warnings(&)
|
|
221
|
+
old_verbose = $VERBOSE
|
|
222
|
+
$VERBOSE = nil
|
|
223
|
+
yield
|
|
224
|
+
ensure
|
|
225
|
+
$VERBOSE = old_verbose
|
|
212
226
|
end
|
|
213
227
|
end
|
|
214
228
|
end
|
data/superconfig.gemspec
CHANGED
|
@@ -1,13 +1,13 @@
|
|
|
1
1
|
# frozen_string_literal: true
|
|
2
2
|
|
|
3
|
-
require_relative "
|
|
3
|
+
require_relative "lib/superconfig"
|
|
4
4
|
|
|
5
5
|
Gem::Specification.new do |spec|
|
|
6
6
|
spec.name = "superconfig"
|
|
7
7
|
spec.version = SuperConfig::VERSION
|
|
8
8
|
spec.authors = ["Nando Vieira"]
|
|
9
9
|
spec.email = ["me@fnando.com"]
|
|
10
|
-
spec.required_ruby_version = Gem::Requirement.new(">=
|
|
10
|
+
spec.required_ruby_version = Gem::Requirement.new(">= 3.1.0")
|
|
11
11
|
spec.metadata = {"rubygems_mfa_required" => "true"}
|
|
12
12
|
|
|
13
13
|
spec.summary = "Access environment variables. Also includes presence " \
|
metadata
CHANGED
|
@@ -1,14 +1,13 @@
|
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
|
2
2
|
name: superconfig
|
|
3
3
|
version: !ruby/object:Gem::Version
|
|
4
|
-
version: 2.
|
|
4
|
+
version: 2.2.1
|
|
5
5
|
platform: ruby
|
|
6
6
|
authors:
|
|
7
7
|
- Nando Vieira
|
|
8
|
-
autorequire:
|
|
9
8
|
bindir: bin
|
|
10
9
|
cert_chain: []
|
|
11
|
-
date:
|
|
10
|
+
date: 2025-02-11 00:00:00.000000000 Z
|
|
12
11
|
dependencies:
|
|
13
12
|
- !ruby/object:Gem::Dependency
|
|
14
13
|
name: bundler
|
|
@@ -169,7 +168,6 @@ licenses:
|
|
|
169
168
|
- MIT
|
|
170
169
|
metadata:
|
|
171
170
|
rubygems_mfa_required: 'true'
|
|
172
|
-
post_install_message:
|
|
173
171
|
rdoc_options: []
|
|
174
172
|
require_paths:
|
|
175
173
|
- lib
|
|
@@ -177,15 +175,14 @@ required_ruby_version: !ruby/object:Gem::Requirement
|
|
|
177
175
|
requirements:
|
|
178
176
|
- - ">="
|
|
179
177
|
- !ruby/object:Gem::Version
|
|
180
|
-
version:
|
|
178
|
+
version: 3.1.0
|
|
181
179
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
|
182
180
|
requirements:
|
|
183
181
|
- - ">="
|
|
184
182
|
- !ruby/object:Gem::Version
|
|
185
183
|
version: '0'
|
|
186
184
|
requirements: []
|
|
187
|
-
rubygems_version: 3.
|
|
188
|
-
signing_key:
|
|
185
|
+
rubygems_version: 3.6.2
|
|
189
186
|
specification_version: 4
|
|
190
187
|
summary: Access environment variables. Also includes presence validation, type coercion
|
|
191
188
|
and default values.
|