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.
Files changed (4) hide show
  1. checksums.yaml +4 -4
  2. data/Gemfile.lock +1 -1
  3. data/lib/bbk/utils/config.rb +11 -8
  4. metadata +1 -1
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: eb2395b2a2bf76b7d8b86eda8feb6ead04cff838c4b2a91d157fe796b4221e8c
4
- data.tar.gz: 046f488594f017991f0255ca9b6b5a1d030ec180541ab0ff5e88b0d872261d92
3
+ metadata.gz: 5a9dd5f6805e9488cae5ff150b2f7ea51a8eca58336d43428f16a6f7a34990cf
4
+ data.tar.gz: 3d6f9115d2e8def51a08249497a52b4750c6b7ccf6c62bd83d7ceb163f3153ee
5
5
  SHA512:
6
- metadata.gz: ba1b4600ac72aa1dbb36ae7834288d664f6aceba8348a9911b96caa1b272300d2145e6b345b75b3176af8960cbadce6d0372250013a056632c5746e308964f39
7
- data.tar.gz: 80eb064b959a9f704829852772e40c7f37643417a567fdf390b766b84e953bc111cfeb03d2ff1766a074a4792f1dd06e7dbbbea1a9397b28cd303ef48c66bf8c
6
+ metadata.gz: 97152af15bb34e112bba23897a836428fec883b5b7b8017bbbe8d241a058d3b0b00685cad35c18f089e5a5abcb08ca46ea81dad9311e01dd2703eabae5e0f4a9
7
+ data.tar.gz: cae731d7f2cb468e5b311e889db29d04ee82cae9b7b956099cc03ecdde90a9a42ea9f7437d87ef4263af84346513e59f3970c8da7a6d2ff436ada6373ad29ad8
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- bbk-utils (1.0.1.97943)
4
+ bbk-utils (1.0.1.97958)
5
5
  activesupport (>= 6.0)
6
6
  russian
7
7
 
@@ -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
- # store.fetch(key.to_s.upcase, default)
137
- if (field = store[key.to_s.upcase]).present? && field.key?(:value)
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][:value]
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][:value]
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][:value]
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,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: bbk-utils
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1.97943
4
+ version: 1.0.1.97958
5
5
  platform: ruby
6
6
  authors:
7
7
  - Samoilenko Yuri