superconfig 2.1.1 → 2.2.0
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 +4 -0
- data/README.md +8 -0
- data/lib/superconfig.rb +42 -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: 38c1ba78820c0d5133c121b5b4157a94c0f49030ae4ae3ee700e231564d4bfc6
|
|
4
|
+
data.tar.gz: '014789c1819732d0b4e213d59189a5c958b60475ec06d71c3d25bdcc1c9bd0f9'
|
|
5
5
|
SHA512:
|
|
6
|
-
metadata.gz:
|
|
7
|
-
data.tar.gz:
|
|
6
|
+
metadata.gz: 43da8d2e33cdbcc32bc1c53d89bec045049500a6dca584d86eb8ce51fa6a14db3104b955d17cab3a5a3f493e831da923226a05399a07b6438ddf93cd3da52e21
|
|
7
|
+
data.tar.gz: 57723e9ac840ddf395a63496836770f4905ee4a2747f77fb72a19b49c8e81a51e1dffd9cff4ec2b99376caf94789d46c7a0a4e0f1750abe60d93b87241ac6b8f
|
|
@@ -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,10 @@ Prefix your message with one of the following:
|
|
|
11
11
|
- [Security] in case of vulnerabilities.
|
|
12
12
|
-->
|
|
13
13
|
|
|
14
|
+
# Unreleased
|
|
15
|
+
|
|
16
|
+
- [Added] `SuperConfig#set(key, value)` method to set arbitrary values.
|
|
17
|
+
|
|
14
18
|
## v2.1.1
|
|
15
19
|
|
|
16
20
|
- [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.0"
|
|
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,25 @@ 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
|
+
property(name) { value }
|
|
86
62
|
end
|
|
87
63
|
|
|
88
64
|
def property(name, func = nil, cache: true, description: nil, &block) # rubocop:disable Lint/UnusedMethodArgument
|
|
89
|
-
callable =
|
|
65
|
+
callable = func || block
|
|
90
66
|
|
|
91
67
|
unless callable
|
|
92
68
|
raise MissingCallable, "arg[1] must respond to #call or pass a block"
|
|
@@ -103,7 +79,7 @@ module SuperConfig
|
|
|
103
79
|
|
|
104
80
|
def credential(name, &block)
|
|
105
81
|
define_singleton_method(name) do
|
|
106
|
-
@__cache__["_credential_#{name}"
|
|
82
|
+
@__cache__[:"_credential_#{name}"] ||= begin
|
|
107
83
|
value = Rails.application.credentials.fetch(name)
|
|
108
84
|
block ? block.call(value) : value # rubocop:disable Performance/RedundantBlockCall
|
|
109
85
|
end
|
|
@@ -208,7 +184,35 @@ module SuperConfig
|
|
|
208
184
|
args = [name, value]
|
|
209
185
|
args << sub_type if sub_type
|
|
210
186
|
|
|
211
|
-
send("coerce_to_#{main_type}", *args)
|
|
187
|
+
send(:"coerce_to_#{main_type}", *args)
|
|
188
|
+
end
|
|
189
|
+
|
|
190
|
+
private def assign(
|
|
191
|
+
name,
|
|
192
|
+
type,
|
|
193
|
+
default = nil,
|
|
194
|
+
required: false,
|
|
195
|
+
aliases: [],
|
|
196
|
+
description: nil
|
|
197
|
+
)
|
|
198
|
+
name = name.to_s
|
|
199
|
+
env_var = name.upcase
|
|
200
|
+
|
|
201
|
+
@attributes[env_var] = {required:, default:}
|
|
202
|
+
|
|
203
|
+
name = "#{name}?" if type == bool
|
|
204
|
+
|
|
205
|
+
validate!(env_var, required, description)
|
|
206
|
+
|
|
207
|
+
define_singleton_method(name) do
|
|
208
|
+
return default unless @env.key?(env_var)
|
|
209
|
+
|
|
210
|
+
coerce(env_var, type, @env[env_var])
|
|
211
|
+
end
|
|
212
|
+
|
|
213
|
+
aliases.each do |alias_name|
|
|
214
|
+
define_singleton_method(alias_name, method(name))
|
|
215
|
+
end
|
|
212
216
|
end
|
|
213
217
|
end
|
|
214
218
|
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.0
|
|
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-10 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.
|