bbk-utils 1.0.1.97943 → 1.0.1.100401
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +2 -2
- data/lib/bbk/utils/config.rb +12 -9
- 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: e1e16290b04a83d41d0dc06d5d334e8beee2cdefc6b83956c0f7a19daa7cfe0a
|
4
|
+
data.tar.gz: adb5a43274bfcfbedafbfd218933983145215ce76d8b85a0b00b3168fe0ae5fc
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e0d0be218d2a7e656e426d00a0a8a92e6b39de71f867dc7c3a8290c183d6b7a4121f4fa3838c36d3ce90b3a43aacceba09accac4c68bd04d05c6b2548bd94cf1
|
7
|
+
data.tar.gz: 830704fde73252acf5b6651113be88ecbeeb28ef84bcc9b4b75cfa9c1c40441896a9930ffee48c112f82580a8c8a7846183d64cbe2711a3694e0af55dff2f6c7
|
data/Gemfile.lock
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
PATH
|
2
2
|
remote: .
|
3
3
|
specs:
|
4
|
-
bbk-utils (1.0.1.
|
4
|
+
bbk-utils (1.0.1.100401)
|
5
5
|
activesupport (>= 6.0)
|
6
6
|
russian
|
7
7
|
|
8
8
|
GEM
|
9
9
|
remote: https://rubygems.org/
|
10
10
|
specs:
|
11
|
-
activesupport (7.0.
|
11
|
+
activesupport (7.0.4)
|
12
12
|
concurrent-ruby (~> 1.0, >= 1.0.2)
|
13
13
|
i18n (>= 1.6, < 2)
|
14
14
|
minitest (>= 5.1)
|
data/lib/bbk/utils/config.rb
CHANGED
@@ -9,6 +9,8 @@ module BBK
|
|
9
9
|
attr_accessor :store, :name
|
10
10
|
attr_reader :prefix, :env_prefix, :parent
|
11
11
|
|
12
|
+
class KeyError < StandardError; end
|
13
|
+
|
12
14
|
class BooleanCaster
|
13
15
|
|
14
16
|
FALSE_VALUES = [
|
@@ -116,7 +118,7 @@ module BBK
|
|
116
118
|
end
|
117
119
|
|
118
120
|
def [](key)
|
119
|
-
self.get(key, search_up: true, search_down: true)
|
121
|
+
self.get(key, search_up: true, search_down: true)[:value]
|
120
122
|
end
|
121
123
|
|
122
124
|
def []=(key, value)
|
@@ -133,12 +135,13 @@ module BBK
|
|
133
135
|
end
|
134
136
|
|
135
137
|
def fetch(key, default = nil)
|
136
|
-
|
137
|
-
|
138
|
-
field[:value]
|
138
|
+
if (rec = self.get(key, search_up: true, search_down: true)) && rec.key?(:value)
|
139
|
+
rec[:value]
|
139
140
|
else
|
140
141
|
default
|
141
142
|
end
|
143
|
+
rescue KeyError
|
144
|
+
default
|
142
145
|
end
|
143
146
|
|
144
147
|
def to_s
|
@@ -160,7 +163,7 @@ module BBK
|
|
160
163
|
end
|
161
164
|
|
162
165
|
def as_json(*_args)
|
163
|
-
values = store_with_subconfigs.sort_by do |item|
|
166
|
+
values = store_with_subconfigs.sort_by do |_key, item|
|
164
167
|
[item[:file].present? ? 0 : 1, item[:required] ? 0 : 1]
|
165
168
|
end.reduce({}) do |ret, item|
|
166
169
|
ret.merge(item[:env] => item)
|
@@ -190,16 +193,16 @@ module BBK
|
|
190
193
|
def get(key, search_up: false, search_down: false)
|
191
194
|
normalized_key = normalize_key(key)
|
192
195
|
if @store.key?(normalized_key)
|
193
|
-
return @store[normalized_key]
|
196
|
+
return @store[normalized_key]
|
194
197
|
end
|
195
198
|
prefix_key = full_prefixed_key(key)
|
196
199
|
if @store.key?(prefix_key)
|
197
|
-
return @store[prefix_key]
|
200
|
+
return @store[prefix_key]
|
198
201
|
end
|
199
202
|
if search_down
|
200
203
|
sub_prefixed_keys(key).each do |pref_key|
|
201
204
|
if @store.key?(pref_key)
|
202
|
-
return @store[pref_key]
|
205
|
+
return @store[pref_key]
|
203
206
|
end
|
204
207
|
|
205
208
|
subconf = @subconfigs.find {|sub| pref_key.starts_with?(sub.env_prefix)}
|
@@ -210,7 +213,7 @@ module BBK
|
|
210
213
|
if search_up && @parent
|
211
214
|
return @parent.get(key, search_up: true, search_down: false)
|
212
215
|
end
|
213
|
-
raise "There is no such key: #{key} in config!"
|
216
|
+
raise KeyError.new("There is no such key: #{key} in config!")
|
214
217
|
end
|
215
218
|
|
216
219
|
def store_with_subconfigs
|
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.0.1.
|
4
|
+
version: 1.0.1.100401
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Samoilenko Yuri
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2022-09-
|
11
|
+
date: 2022-09-20 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activesupport
|