umbrellio-utils 0.3.0 → 0.3.1

This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7ad8f07af559cdaaabcb97428722b18a80109a4719922f2e32a3f1ab32b40dba
4
- data.tar.gz: 47d944ce423bd48a3e1fb8e56601a97e184830fdd696f2322acc97e4e75058d1
3
+ metadata.gz: e701149e2cc866576a584afb0ce4f0260def90172435574b54a76fa360cccc6f
4
+ data.tar.gz: 3ade3ca53aeb50fcab231798611f1810875e483e55eacdbfd31d111b161977b7
5
5
  SHA512:
6
- metadata.gz: 01fb5c648f8789a1feb93cf6aa8f1664798eb416f0a9d37048f90da4dd6d0ce402b9ce87436ff9dee75617ba372ee0b9c1a11db082c8a8763cc4cf0f3d988789
7
- data.tar.gz: 5cb141aa1495ba285ffe2afaf0fed3acfb256f520b98ce555e6c882e9ff9ac584e7bfb284b949dd31462b141a13d63c9ee48248a5d7a24c2285ad9b260946792
6
+ metadata.gz: 66a5e895a307e11876af84245aa5efd02c8826643bf4ef15ef897222e47c26bbc44acfc33d8f174e776656a41389257eb7aceaa9efdbe243067db0b3fa7638d7
7
+ data.tar.gz: 2e7a2a4a186c4d4f5772bafced3d3486b97fbe25a75316ca473f901798eecba57e9b8c2170f23b4a868b2f77ac233b1de946df7b1d23ab7fa260764de8375835
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- umbrellio-utils (0.3.0)
4
+ umbrellio-utils (0.3.1)
5
5
  memery (~> 1)
6
6
 
7
7
  GEM
@@ -114,6 +114,7 @@ PLATFORMS
114
114
  x86_64-linux
115
115
 
116
116
  DEPENDENCIES
117
+ activesupport
117
118
  bundler
118
119
  bundler-audit
119
120
  ci-helper
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, which accepts a block.
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 hash, which you want to expand
68
- # @param [String] delemiter, separator, which is used in the value of the keys
69
- # @param [Proc, Lambda, Symbol] key_converter, converter for key's value.
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, delemiter: ".", key_converter: :to_sym)
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(delemiter).map(&key_converter)
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, hash, which you want to expand
92
- # @param [Hash] **expand_hash_options options, that the
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
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UmbrellioUtils
4
- VERSION = "0.3.0"
4
+ VERSION = "0.3.1"
5
5
  end
@@ -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.0
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-04-16 00:00:00.000000000 Z
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.15
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