umbrellio-utils 0.1.0 → 0.2.0

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: 7a8a024f0f4fc2df65b3ec0a9e8bfafc71122522cc9e633dec609ed7f03f1a59
4
- data.tar.gz: 5e66a79927988a0a2232308315d8e0e07ccb3fcb40c9c770963babd81f77e47e
3
+ metadata.gz: f09a52e459529d80c1d72569930d27d97d470c5e0fe54955e0c877e5144f8ca8
4
+ data.tar.gz: 9f1bc2c3e3e6508e2f7fcfe5a980fe2a0e38cd889f75ea4e596c2d4b7323f0e5
5
5
  SHA512:
6
- metadata.gz: d8a5425810747fb97922019b388e54358623b39d119ea0482592d39f3ffda8efa54768b20d896ebcac3b2877059da24212ff2811c255eb29506108946309d8c4
7
- data.tar.gz: e918d6b8324560d613fef02b68625373b6285b8a9791bbf5072c1a1bb0117b73f9699edc508f2456d88b7a3307cbc3ba42a86103f554518685b539efb3fd1728
6
+ metadata.gz: 2d566f694d524defa6e321dd62df3cb762ce1adab4b026397d7592254c1f9b06f7b896e39e5ab4192a2558aee394063bb34f58176666d5f78da9e8291b5cf9de
7
+ data.tar.gz: 8767c6c8428665f5b4d2c150fabfd9b9a4118fc122a8e3582fc4e923ab92999ad9101e4a75b24a7d7b293327332ef8078a5a4ecad1f5e3984bc9bf679700eda8
data/.editorconfig ADDED
@@ -0,0 +1,9 @@
1
+ root = true
2
+
3
+ [*]
4
+ indent_style = space
5
+ indent_size = 2
6
+ end_of_line = lf
7
+ charset = utf-8
8
+ trim_trailing_whitespace = true
9
+ insert_final_newline = true
data/.rubocop.yml CHANGED
@@ -17,3 +17,7 @@ Naming/FileName:
17
17
 
18
18
  Naming/RescuedExceptionsVariableName:
19
19
  Enabled: false
20
+
21
+ Style/HashConversion:
22
+ Exclude:
23
+ - spec/**/*_spec.rb
data/LICENSE.txt CHANGED
@@ -1,6 +1,6 @@
1
1
  The MIT License (MIT)
2
2
 
3
- Copyright (c) 2020 JustAnotherDude
3
+ Copyright (c) 2021 Umbrellio
4
4
 
5
5
  Permission is hereby granted, free of charge, to any person obtaining a copy
6
6
  of this software and associated documentation files (the "Software"), to deal
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
 
@@ -3,9 +3,7 @@
3
3
  require "memery"
4
4
 
5
5
  module UmbrellioUtils
6
- CONFIG_SET_MUTEX = Mutex.new
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
- CONFIG_SET_MUTEX.synchronize do
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
- CONFIG_MUTEX.synchronize { yield config }
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
- EXTENSION_MUTEX.synchronize { const.class_eval(&block) }
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
@@ -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
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UmbrellioUtils
4
- VERSION = "0.1.0"
4
+ VERSION = "0.2.0"
5
5
  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.1.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-01 00:00:00.000000000 Z
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"