bbk-utils 1.1.0.181866 → 1.1.0.273317
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +19 -3
- data/lib/bbk/utils/config.rb +46 -43
- data/sig/bbk/config.rbs +4 -4
- data/sig/env.rbs +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 92bd4633caa38405fd9ec5f01f101842716c0808c3bc86776c4880d0120006c1
|
4
|
+
data.tar.gz: 3593415e0eec611b5ca305a4d5ba6f59c92591943b00c9c96415f5bfc6441b4a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 90f54d3498b381d24f737147ce5eaf7f5ca717a44c2e830ff307fa41616f5866e5c2f3dba3fe1495904b15da1480d24691f90113c97ede2ea1d4e04c7c7d532c
|
7
|
+
data.tar.gz: 3306151c09eba11399f139134d65457d52d355fd7b23a59cb056ba2a6f901c4e7744d47acb0d56fe5d86ce3441ad1dde05589f46a3b2beb6d2fbdec0d113f399
|
data/Gemfile.lock
CHANGED
@@ -1,17 +1,25 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
bbk-utils (1.1.0.
|
4
|
+
bbk-utils (1.1.0.273317)
|
5
5
|
activesupport (>= 7.0)
|
6
6
|
russian
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activesupport (7.
|
11
|
+
activesupport (7.1.5)
|
12
|
+
base64
|
13
|
+
benchmark (>= 0.3)
|
14
|
+
bigdecimal
|
12
15
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
16
|
+
connection_pool (>= 2.2.5)
|
17
|
+
drb
|
13
18
|
i18n (>= 1.6, < 2)
|
19
|
+
logger (>= 1.4.2)
|
14
20
|
minitest (>= 5.1)
|
21
|
+
mutex_m
|
22
|
+
securerandom (>= 0.3)
|
15
23
|
tzinfo (~> 2.0)
|
16
24
|
addressable (2.8.0)
|
17
25
|
public_suffix (>= 2.0.2, < 5.0)
|
@@ -21,14 +29,19 @@ GEM
|
|
21
29
|
descendants_tracker (~> 0.0.4)
|
22
30
|
ice_nine (~> 0.11.0)
|
23
31
|
thread_safe (~> 0.3, >= 0.3.1)
|
32
|
+
base64 (0.2.0)
|
33
|
+
benchmark (0.4.0)
|
34
|
+
bigdecimal (3.1.8)
|
24
35
|
byebug (11.1.3)
|
25
36
|
coercible (1.0.0)
|
26
37
|
descendants_tracker (~> 0.0.1)
|
27
38
|
concurrent-ruby (1.2.2)
|
39
|
+
connection_pool (2.4.1)
|
28
40
|
descendants_tracker (0.0.4)
|
29
41
|
thread_safe (~> 0.3, >= 0.3.1)
|
30
42
|
diff-lcs (1.4.4)
|
31
43
|
docile (1.4.0)
|
44
|
+
drb (2.2.1)
|
32
45
|
equalizer (0.0.11)
|
33
46
|
erubis (2.7.0)
|
34
47
|
faker (2.19.0)
|
@@ -48,7 +61,9 @@ GEM
|
|
48
61
|
kwalify (0.7.2)
|
49
62
|
launchy (2.5.0)
|
50
63
|
addressable (~> 2.7)
|
51
|
-
|
64
|
+
logger (1.6.1)
|
65
|
+
minitest (5.25.1)
|
66
|
+
mutex_m (0.2.0)
|
52
67
|
parallel (1.21.0)
|
53
68
|
parser (3.0.3.1)
|
54
69
|
ast (~> 2.4.1)
|
@@ -106,6 +121,7 @@ GEM
|
|
106
121
|
virtus (~> 1.0)
|
107
122
|
russian (0.6.0)
|
108
123
|
i18n (>= 0.5.0)
|
124
|
+
securerandom (0.3.2)
|
109
125
|
sexp_processor (4.16.0)
|
110
126
|
simplecov (0.21.2)
|
111
127
|
docile (~> 1.1)
|
data/lib/bbk/utils/config.rb
CHANGED
@@ -4,7 +4,7 @@ module BBK
|
|
4
4
|
module Utils
|
5
5
|
class Config
|
6
6
|
|
7
|
-
PREFIX_SEP = '_'
|
7
|
+
PREFIX_SEP = '_'
|
8
8
|
|
9
9
|
attr_accessor :store, :name
|
10
10
|
attr_reader :prefix, :env_prefix, :parent
|
@@ -60,8 +60,11 @@ module BBK
|
|
60
60
|
@env_prefix = normalize_key(@prefixes.join(PREFIX_SEP))
|
61
61
|
end
|
62
62
|
|
63
|
-
def map(env, file, required: true, desc: nil, bool: false, key: nil)
|
64
|
-
|
63
|
+
def map(env, file, required: true, desc: nil, bool: false, key: nil, rewrite: true)
|
64
|
+
conf_key = full_prefixed_key(env)
|
65
|
+
return if @store.key?(conf_key) && !rewrite
|
66
|
+
|
67
|
+
@store[conf_key] = {
|
65
68
|
env: full_prefixed_key(key || env),
|
66
69
|
file: file,
|
67
70
|
required: required,
|
@@ -71,11 +74,14 @@ module BBK
|
|
71
74
|
}
|
72
75
|
end
|
73
76
|
|
74
|
-
def require(env, desc: nil, bool: false, type: nil, key: nil)
|
77
|
+
def require(env, desc: nil, bool: false, type: nil, key: nil, rewrite: true)
|
75
78
|
raise ArgumentError.new('Specified type and bool') if bool && type.present?
|
76
79
|
|
77
80
|
type = BBK::Config::BooleanCaster.singleton_method(:cast) if bool
|
78
|
-
|
81
|
+
conf_key = full_prefixed_key(env)
|
82
|
+
return if @store.key?(conf_key) && !rewrite
|
83
|
+
|
84
|
+
@store[conf_key] = {
|
79
85
|
env: full_prefixed_key(key || env),
|
80
86
|
file: nil,
|
81
87
|
required: true,
|
@@ -85,11 +91,14 @@ module BBK
|
|
85
91
|
}
|
86
92
|
end
|
87
93
|
|
88
|
-
def optional(env, default: nil, desc: nil, bool: false, type: nil, key: nil)
|
94
|
+
def optional(env, default: nil, desc: nil, bool: false, type: nil, key: nil, rewrite: true)
|
89
95
|
raise ArgumentError.new('Specified type and bool') if bool && type.present?
|
90
96
|
|
91
97
|
type = BBK::Utils::Config::BooleanCaster.singleton_method(:cast) if bool
|
92
|
-
|
98
|
+
conf_key = full_prefixed_key(env)
|
99
|
+
return if @store.key?(conf_key) && !rewrite
|
100
|
+
|
101
|
+
@store[conf_key] = {
|
93
102
|
env: full_prefixed_key(key || env),
|
94
103
|
file: nil,
|
95
104
|
required: false,
|
@@ -104,17 +113,16 @@ module BBK
|
|
104
113
|
@store.each_value do |item|
|
105
114
|
process(source, item)
|
106
115
|
end
|
107
|
-
@subconfigs.each {|sub| sub.run!(source)}
|
116
|
+
@subconfigs.each {|sub| sub.run!(source) }
|
108
117
|
nil
|
109
118
|
end
|
110
119
|
|
111
|
-
def subconfig(prefix
|
120
|
+
def subconfig(prefix:, name: nil)
|
112
121
|
raise ArgumentError.new("Subconfig with prefix #{prefix} already exists") if @subconfigs.any? {|sub| sub.prefix == prefix.to_s }
|
122
|
+
|
113
123
|
sub = self.class.new(name: name, prefix: prefix, parent: self)
|
114
124
|
@subconfigs << sub
|
115
|
-
if block_given?
|
116
|
-
yield sub
|
117
|
-
end
|
125
|
+
yield sub if block_given?
|
118
126
|
sub
|
119
127
|
end
|
120
128
|
|
@@ -187,48 +195,43 @@ module BBK
|
|
187
195
|
|
188
196
|
protected
|
189
197
|
|
190
|
-
|
191
|
-
@prefixes
|
192
|
-
end
|
198
|
+
attr_reader :prefixes
|
193
199
|
|
194
|
-
|
195
|
-
|
196
|
-
|
197
|
-
|
198
|
-
|
199
|
-
|
200
|
-
if @store.key?(prefix_key)
|
201
|
-
return @store[prefix_key]
|
202
|
-
end
|
203
|
-
if search_down
|
204
|
-
sub_prefixed_keys(key).each do |pref_key|
|
205
|
-
if @store.key?(pref_key)
|
206
|
-
return @store[pref_key]
|
207
|
-
end
|
200
|
+
def get(key, search_up: false, search_down: false)
|
201
|
+
normalized_key = normalize_key(key)
|
202
|
+
return @store[normalized_key] if @store.key?(normalized_key)
|
203
|
+
|
204
|
+
prefix_key = full_prefixed_key(key)
|
205
|
+
return @store[prefix_key] if @store.key?(prefix_key)
|
208
206
|
|
209
|
-
|
210
|
-
|
211
|
-
|
207
|
+
if search_down
|
208
|
+
sub_prefixed_keys(key).each do |pref_key|
|
209
|
+
return @store[pref_key] if @store.key?(pref_key)
|
210
|
+
|
211
|
+
subconf = @subconfigs.find {|sub| pref_key.starts_with?(sub.env_prefix) }
|
212
|
+
next if subconf.nil?
|
213
|
+
|
214
|
+
return subconf.get(pref_key, search_up: false, search_down: true)
|
215
|
+
end
|
212
216
|
end
|
217
|
+
return @parent.get(key, search_up: true, search_down: false) if search_up && @parent
|
218
|
+
|
219
|
+
raise KeyError.new("There is no such key: #{key} in config!")
|
213
220
|
end
|
214
|
-
if search_up && @parent
|
215
|
-
return @parent.get(key, search_up: true, search_down: false)
|
216
|
-
end
|
217
|
-
raise KeyError.new("There is no such key: #{key} in config!")
|
218
|
-
end
|
219
221
|
|
220
|
-
|
221
|
-
|
222
|
-
|
223
|
-
|
222
|
+
def store_with_subconfigs
|
223
|
+
res = @store.dup
|
224
|
+
@subconfigs.each do |sub|
|
225
|
+
res = res.merge(sub.store_with_subconfigs)
|
226
|
+
end
|
227
|
+
res
|
224
228
|
end
|
225
|
-
res
|
226
|
-
end
|
227
229
|
|
228
230
|
private
|
229
231
|
|
230
232
|
def normalize_key(key)
|
231
233
|
return nil if key.nil?
|
234
|
+
|
232
235
|
key.to_s.upcase.gsub('-', '_')
|
233
236
|
end
|
234
237
|
|
data/sig/bbk/config.rbs
CHANGED
@@ -17,7 +17,7 @@ module BBK
|
|
17
17
|
|
18
18
|
type typeCaster = _CallableCaster | _ClassCaster
|
19
19
|
type configItem = {env: String, file: String?, required: bool, desc: String?, bool: bool, value: untyped, default: untyped, type: typeCaster?}
|
20
|
-
type envSource =
|
20
|
+
type envSource = ENVClass | _ENV
|
21
21
|
|
22
22
|
attr_accessor store: untyped
|
23
23
|
attr_accessor name: String?
|
@@ -25,9 +25,9 @@ module BBK
|
|
25
25
|
def self.instance: () -> instance
|
26
26
|
|
27
27
|
def initialize: (?name: String?, ?prefix: String?, ?parent: BBK::Utils::Config?) -> void
|
28
|
-
def map: (envSource env, String file, ?required: bool, ?desc: String, ?bool: bool, ?key: String) -> void
|
29
|
-
def require: (envSource env, ?desc: String?, ?bool: bool, ?type: typeCaster, ?key: String?) -> void
|
30
|
-
def optional: (envSource env, ?default: untyped, ?desc: String, ?bool: bool, ?type: typeCaster, ?key: String) -> void
|
28
|
+
def map: (envSource env, String file, ?required: bool, ?desc: String, ?bool: bool, ?key: String, ?rewrite: bool) -> void
|
29
|
+
def require: (envSource env, ?desc: String?, ?bool: bool, ?type: typeCaster, ?key: String?, ?rewrite: bool) -> void
|
30
|
+
def optional: (envSource env, ?default: untyped, ?desc: String, ?bool: bool, ?type: typeCaster, ?key: String, ?rewrite: bool) -> void
|
31
31
|
|
32
32
|
def run!: (?envSource source) -> void
|
33
33
|
def []: (String key) -> untyped
|
data/sig/env.rbs
CHANGED
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: bbk-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 1.1.0.
|
4
|
+
version: 1.1.0.273317
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samoilenko Yuri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date:
|
11
|
+
date: 2024-11-15 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|