bbk-utils 1.0.1.97943 → 1.0.1.97958
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile.lock +1 -1
- data/lib/bbk/utils/config.rb +11 -8
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 5a9dd5f6805e9488cae5ff150b2f7ea51a8eca58336d43428f16a6f7a34990cf
|
4
|
+
data.tar.gz: 3d6f9115d2e8def51a08249497a52b4750c6b7ccf6c62bd83d7ceb163f3153ee
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 97152af15bb34e112bba23897a836428fec883b5b7b8017bbbe8d241a058d3b0b00685cad35c18f089e5a5abcb08ca46ea81dad9311e01dd2703eabae5e0f4a9
|
7
|
+
data.tar.gz: cae731d7f2cb468e5b311e889db29d04ee82cae9b7b956099cc03ecdde90a9a42ea9f7437d87ef4263af84346513e59f3970c8da7a6d2ff436ada6373ad29ad8
|
data/Gemfile.lock
CHANGED
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
|
@@ -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
|