umbrellio-utils 0.1.0 → 0.2.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/.editorconfig +9 -0
- data/.rubocop.yml +4 -0
- data/LICENSE.txt +1 -1
- data/README.md +1 -1
- data/lib/umbrellio_utils.rb +8 -6
- data/lib/umbrellio_utils/formatting.rb +14 -0
- data/lib/umbrellio_utils/misc.rb +4 -0
- data/lib/umbrellio_utils/version.rb +1 -1
- metadata +3 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: f09a52e459529d80c1d72569930d27d97d470c5e0fe54955e0c877e5144f8ca8
|
4
|
+
data.tar.gz: 9f1bc2c3e3e6508e2f7fcfe5a980fe2a0e38cd889f75ea4e596c2d4b7323f0e5
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 2d566f694d524defa6e321dd62df3cb762ce1adab4b026397d7592254c1f9b06f7b896e39e5ab4192a2558aee394063bb34f58176666d5f78da9e8291b5cf9de
|
7
|
+
data.tar.gz: 8767c6c8428665f5b4d2c150fabfd9b9a4118fc122a8e3582fc4e923ab92999ad9101e4a75b24a7d7b293327332ef8078a5a4ecad1f5e3984bc9bf679700eda8
|
data/.editorconfig
ADDED
data/.rubocop.yml
CHANGED
data/LICENSE.txt
CHANGED
data/README.md
CHANGED
@@ -1,4 +1,4 @@
|
|
1
|
-
# Umbrellio Utils
|
1
|
+
# Umbrellio Utils [![Gem Version](https://badge.fury.io/rb/umbrellio-utils.svg)](https://badge.fury.io/rb/umbrellio-utils) [![Coverage Status](https://coveralls.io/repos/github/umbrellio/utils/badge.svg?branch=main)](https://coveralls.io/github/umbrellio/utils?branch=main)
|
2
2
|
|
3
3
|
## Installation
|
4
4
|
|
data/lib/umbrellio_utils.rb
CHANGED
@@ -3,9 +3,7 @@
|
|
3
3
|
require "memery"
|
4
4
|
|
5
5
|
module UmbrellioUtils
|
6
|
-
|
7
|
-
CONFIG_MUTEX = Mutex.new
|
8
|
-
EXTENSION_MUTEX = Mutex.new
|
6
|
+
GLOBAL_MUTEX = Mutex.new
|
9
7
|
|
10
8
|
Dir["#{__dir__}/*/*.rb"].each { |file_path| require_relative(file_path) }
|
11
9
|
|
@@ -18,7 +16,7 @@ module UmbrellioUtils
|
|
18
16
|
|
19
17
|
# rubocop:disable Style/ClassVars
|
20
18
|
def config
|
21
|
-
|
19
|
+
synchronize do
|
22
20
|
@@config ||= Struct
|
23
21
|
.new(:store_table_name, :http_client_name, keyword_init: true)
|
24
22
|
.new(**default_settings)
|
@@ -28,12 +26,12 @@ module UmbrellioUtils
|
|
28
26
|
# rubocop:enable Style/ClassVars
|
29
27
|
|
30
28
|
def configure
|
31
|
-
|
29
|
+
synchronize { yield config }
|
32
30
|
end
|
33
31
|
|
34
32
|
def extend_util!(module_name, &block)
|
35
33
|
const = UmbrellioUtils.const_get(module_name)
|
36
|
-
|
34
|
+
synchronize { const.class_eval(&block) }
|
37
35
|
end
|
38
36
|
|
39
37
|
private
|
@@ -44,4 +42,8 @@ module UmbrellioUtils
|
|
44
42
|
http_client_name: :application_httpclient,
|
45
43
|
}
|
46
44
|
end
|
45
|
+
|
46
|
+
def synchronize(&block)
|
47
|
+
GLOBAL_MUTEX.owned? ? yield : GLOBAL_MUTEX.synchronize(&block)
|
48
|
+
end
|
47
49
|
end
|
@@ -60,5 +60,19 @@ module UmbrellioUtils
|
|
60
60
|
def to_date_part_string(part)
|
61
61
|
format("%<part>02d", part: part)
|
62
62
|
end
|
63
|
+
|
64
|
+
def expand_hash(hash, delemiter: ".", key_converter: :to_sym)
|
65
|
+
hash.each_with_object(Misc.build_infinite_hash) do |entry, memo|
|
66
|
+
path, value = entry
|
67
|
+
*path_to_key, key = path.to_s.split(delemiter).map(&key_converter)
|
68
|
+
|
69
|
+
if path_to_key.empty?
|
70
|
+
memo[key] = value
|
71
|
+
else
|
72
|
+
resolved_hash = memo.dig(*path_to_key)
|
73
|
+
resolved_hash[key] = value
|
74
|
+
end
|
75
|
+
end
|
76
|
+
end
|
63
77
|
end
|
64
78
|
end
|
data/lib/umbrellio_utils/misc.rb
CHANGED
@@ -24,5 +24,9 @@ module UmbrellioUtils
|
|
24
24
|
ranges = ranges.map { |x| x.present? && x.size == 2 ? x : [nil, nil] }
|
25
25
|
ranges.first.zip(*ranges[1..]).map { |x| x.find(&:present?) }
|
26
26
|
end
|
27
|
+
|
28
|
+
def build_infinite_hash
|
29
|
+
Hash.new { |hash, key| hash[key] = Hash.new(&hash.default_proc) }
|
30
|
+
end
|
27
31
|
end
|
28
32
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: umbrellio-utils
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.
|
4
|
+
version: 0.2.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JustAnotherDude
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-04-
|
11
|
+
date: 2021-04-06 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: memery
|
@@ -157,6 +157,7 @@ executables: []
|
|
157
157
|
extensions: []
|
158
158
|
extra_rdoc_files: []
|
159
159
|
files:
|
160
|
+
- ".editorconfig"
|
160
161
|
- ".github/workflows/test.yml"
|
161
162
|
- ".gitignore"
|
162
163
|
- ".rspec"
|