umbrellio-utils 0.3.0 → 0.3.1
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 -1
- data/README.md +1 -1
- data/lib/umbrellio_utils/formatting.rb +10 -8
- data/lib/umbrellio_utils/misc.rb +34 -0
- data/lib/umbrellio_utils/version.rb +1 -1
- data/umbrellio_utils.gemspec +1 -0
- metadata +17 -3
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: e701149e2cc866576a584afb0ce4f0260def90172435574b54a76fa360cccc6f
|
4
|
+
data.tar.gz: 3ade3ca53aeb50fcab231798611f1810875e483e55eacdbfd31d111b161977b7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 66a5e895a307e11876af84245aa5efd02c8826643bf4ef15ef897222e47c26bbc44acfc33d8f174e776656a41389257eb7aceaa9efdbe243067db0b3fa7638d7
|
7
|
+
data.tar.gz: 2e7a2a4a186c4d4f5772bafced3d3486b97fbe25a75316ca473f901798eecba57e9b8c2170f23b4a868b2f77ac233b1de946df7b1d23ab7fa260764de8375835
|
data/Gemfile.lock
CHANGED
data/README.md
CHANGED
@@ -52,7 +52,7 @@ Some modules and classes are configurable. Here's the full list of settings and
|
|
52
52
|
`UmbrellioUtils::HTTPClient`. Defaults to `:application_httpclient`
|
53
53
|
|
54
54
|
You can change config in two ways. Firstly, you can change values by accessing configuration
|
55
|
-
directly. Secondly, you can use `UmbrellioUtils::configure` method
|
55
|
+
directly. Secondly, you can use `UmbrellioUtils::configure` method which accepts a block.
|
56
56
|
|
57
57
|
```ruby
|
58
58
|
|
@@ -64,17 +64,17 @@ module UmbrellioUtils
|
|
64
64
|
#
|
65
65
|
# Expands a hash whose keys contain the path.
|
66
66
|
#
|
67
|
-
# @param [Hash] hash
|
68
|
-
# @param [String]
|
69
|
-
# @param [Proc, Lambda, Symbol]
|
67
|
+
# @param hash [Hash] hash which you want to expand
|
68
|
+
# @param delimiter [String] separator which is used in the value of the keys
|
69
|
+
# @param key_converter [Proc, Lambda, Symbol] converter for key's value.
|
70
70
|
# Defaults to :to_sym
|
71
71
|
#
|
72
72
|
# @return [Hash] expanded hash
|
73
73
|
#
|
74
|
-
def expand_hash(hash,
|
75
|
-
hash.each_with_object(Misc.build_infinite_hash) do |entry, memo|
|
74
|
+
def expand_hash(hash, delimiter: ".", key_converter: :to_sym)
|
75
|
+
result = hash.each_with_object(Misc.build_infinite_hash) do |entry, memo|
|
76
76
|
path, value = entry
|
77
|
-
*path_to_key, key = path.to_s.split(
|
77
|
+
*path_to_key, key = path.to_s.split(delimiter).map(&key_converter)
|
78
78
|
|
79
79
|
if path_to_key.empty?
|
80
80
|
memo[key] = value
|
@@ -83,13 +83,15 @@ module UmbrellioUtils
|
|
83
83
|
resolved_hash[key] = value
|
84
84
|
end
|
85
85
|
end
|
86
|
+
|
87
|
+
Misc.reset_defaults_for_hash(result)
|
86
88
|
end
|
87
89
|
|
88
90
|
#
|
89
91
|
# Expands a nested hash whose keys contain the path.
|
90
92
|
#
|
91
|
-
# @param [Hash] hash
|
92
|
-
# @param [Hash]
|
93
|
+
# @param hash [Hash] hash which you want to expand
|
94
|
+
# @param **expand_hash_options [Hash] options, that the
|
93
95
|
# {#expand_hash} method accepts
|
94
96
|
#
|
95
97
|
# @return [Hash] expanded hash
|
data/lib/umbrellio_utils/misc.rb
CHANGED
@@ -19,14 +19,48 @@ module UmbrellioUtils
|
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
22
|
+
#
|
22
23
|
# Ranges go from high to low priority
|
24
|
+
#
|
23
25
|
def merge_ranges(*ranges)
|
24
26
|
ranges = ranges.map { |x| x.present? && x.size == 2 ? x : [nil, nil] }
|
25
27
|
ranges.first.zip(*ranges[1..]).map { |x| x.find(&:present?) }
|
26
28
|
end
|
27
29
|
|
30
|
+
#
|
31
|
+
# Builds empty hash which recursively returns empty hash, if key is not found.
|
32
|
+
# Also note, that this hash and all subhashes has set #default_proc.
|
33
|
+
# To reset this attribute use {#reset_defaults_for_hash}
|
34
|
+
#
|
35
|
+
# @example Dig to key
|
36
|
+
# h = UmbrellioUtils::Misc.build_infinite_hash => {}
|
37
|
+
# h.dig(:kek, :pek) => {}
|
38
|
+
# h => { kek: { pek: {} } }
|
39
|
+
#
|
40
|
+
# @return [Hash] empty infinite hash.
|
41
|
+
#
|
28
42
|
def build_infinite_hash
|
29
43
|
Hash.new { |hash, key| hash[key] = Hash.new(&hash.default_proc) }
|
30
44
|
end
|
45
|
+
|
46
|
+
#
|
47
|
+
# Deeply sets #default and #default_proc values to nil.
|
48
|
+
#
|
49
|
+
# @param hash [Hash] hash for which you want to reset defaults.
|
50
|
+
#
|
51
|
+
# @return [Hash] reset hash.
|
52
|
+
#
|
53
|
+
def reset_defaults_for_hash(hash)
|
54
|
+
hash.dup.tap do |dup_hash|
|
55
|
+
dup_hash.default = nil
|
56
|
+
dup_hash.default_proc = nil
|
57
|
+
|
58
|
+
dup_hash.transform_values! do |obj|
|
59
|
+
next obj.deep_dup unless obj.is_a?(Hash)
|
60
|
+
|
61
|
+
reset_defaults_for_hash(obj)
|
62
|
+
end
|
63
|
+
end
|
64
|
+
end
|
31
65
|
end
|
32
66
|
end
|
data/umbrellio_utils.gemspec
CHANGED
@@ -29,6 +29,7 @@ Gem::Specification.new do |spec|
|
|
29
29
|
|
30
30
|
spec.add_dependency "memery", "~> 1"
|
31
31
|
|
32
|
+
spec.add_development_dependency "activesupport"
|
32
33
|
spec.add_development_dependency "bundler"
|
33
34
|
spec.add_development_dependency "bundler-audit"
|
34
35
|
spec.add_development_dependency "ci-helper"
|
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.3.
|
4
|
+
version: 0.3.1
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- JustAnotherDude
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2021-
|
11
|
+
date: 2021-06-08 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: memery
|
@@ -24,6 +24,20 @@ dependencies:
|
|
24
24
|
- - "~>"
|
25
25
|
- !ruby/object:Gem::Version
|
26
26
|
version: '1'
|
27
|
+
- !ruby/object:Gem::Dependency
|
28
|
+
name: activesupport
|
29
|
+
requirement: !ruby/object:Gem::Requirement
|
30
|
+
requirements:
|
31
|
+
- - ">="
|
32
|
+
- !ruby/object:Gem::Version
|
33
|
+
version: '0'
|
34
|
+
type: :development
|
35
|
+
prerelease: false
|
36
|
+
version_requirements: !ruby/object:Gem::Requirement
|
37
|
+
requirements:
|
38
|
+
- - ">="
|
39
|
+
- !ruby/object:Gem::Version
|
40
|
+
version: '0'
|
27
41
|
- !ruby/object:Gem::Dependency
|
28
42
|
name: bundler
|
29
43
|
requirement: !ruby/object:Gem::Requirement
|
@@ -224,7 +238,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
|
|
224
238
|
- !ruby/object:Gem::Version
|
225
239
|
version: '0'
|
226
240
|
requirements: []
|
227
|
-
rubygems_version: 3.2.
|
241
|
+
rubygems_version: 3.2.18
|
228
242
|
signing_key:
|
229
243
|
specification_version: 4
|
230
244
|
summary: A set of utilities that speed up development
|