umbrellio-utils 0.1.0 → 0.3.2

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: 7a8a024f0f4fc2df65b3ec0a9e8bfafc71122522cc9e633dec609ed7f03f1a59
4
- data.tar.gz: 5e66a79927988a0a2232308315d8e0e07ccb3fcb40c9c770963babd81f77e47e
3
+ metadata.gz: 2b63180fc355a29f6d9890b540e8fadfbc572070865b7309990de0bd0fc094ec
4
+ data.tar.gz: 801fc30c7238f126b9fe705471be9d8d66f9b575e1789bd239d1868df323dfa8
5
5
  SHA512:
6
- metadata.gz: d8a5425810747fb97922019b388e54358623b39d119ea0482592d39f3ffda8efa54768b20d896ebcac3b2877059da24212ff2811c255eb29506108946309d8c4
7
- data.tar.gz: e918d6b8324560d613fef02b68625373b6285b8a9791bbf5072c1a1bb0117b73f9699edc508f2456d88b7a3307cbc3ba42a86103f554518685b539efb3fd1728
6
+ metadata.gz: 1187dc1b14d139bb723e11be25e7a35412cc794618913272c10b9aeff8e5a98392525fc75bbfead6b6a59e7c8c37c305c7d27164eb2148da28540fad19ea1aac
7
+ data.tar.gz: b4c696407bc41fb6ce2df840cb4476e99cdf68016e50a28545a33dcba615bc1dfd5b9c8822e5d357454207758538cd89b370b2efdf94ab950bfab74355ed5309
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/.gitignore CHANGED
@@ -6,5 +6,3 @@
6
6
  /pkg/
7
7
  /spec/reports/
8
8
  /tmp/
9
-
10
- Gemfile.lock
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/Gemfile.lock ADDED
@@ -0,0 +1,140 @@
1
+ PATH
2
+ remote: .
3
+ specs:
4
+ umbrellio-utils (0.3.2)
5
+ memery (~> 1)
6
+
7
+ GEM
8
+ remote: https://rubygems.org/
9
+ specs:
10
+ activesupport (6.1.3.1)
11
+ concurrent-ruby (~> 1.0, >= 1.0.2)
12
+ i18n (>= 1.6, < 2)
13
+ minitest (>= 5.1)
14
+ tzinfo (~> 2.0)
15
+ zeitwerk (~> 2.3)
16
+ ast (2.4.2)
17
+ bundler-audit (0.8.0)
18
+ bundler (>= 1.2.0, < 3)
19
+ thor (~> 1.0)
20
+ ci-helper (0.4.2)
21
+ colorize (~> 0.8)
22
+ dry-inflector (~> 0.2)
23
+ umbrellio-sequel-plugins (~> 0.4)
24
+ coderay (1.1.3)
25
+ colorize (0.8.1)
26
+ concurrent-ruby (1.1.8)
27
+ diff-lcs (1.4.4)
28
+ docile (1.3.5)
29
+ dry-inflector (0.2.0)
30
+ i18n (1.8.10)
31
+ concurrent-ruby (~> 1.0)
32
+ memery (1.4.1)
33
+ ruby2_keywords (~> 0.0.2)
34
+ method_source (1.0.0)
35
+ minitest (5.14.4)
36
+ nokogiri (1.12.2-x86_64-darwin)
37
+ racc (~> 1.4)
38
+ nokogiri (1.12.2-x86_64-linux)
39
+ racc (~> 1.4)
40
+ nori (2.6.0)
41
+ parallel (1.20.1)
42
+ parser (3.0.1.0)
43
+ ast (~> 2.4.1)
44
+ pry (0.14.0)
45
+ coderay (~> 1.1)
46
+ method_source (~> 1.0)
47
+ racc (1.5.2)
48
+ rack (2.2.3)
49
+ rainbow (3.0.0)
50
+ rake (13.0.3)
51
+ regexp_parser (2.1.1)
52
+ rexml (3.2.5)
53
+ rspec (3.10.0)
54
+ rspec-core (~> 3.10.0)
55
+ rspec-expectations (~> 3.10.0)
56
+ rspec-mocks (~> 3.10.0)
57
+ rspec-core (3.10.1)
58
+ rspec-support (~> 3.10.0)
59
+ rspec-expectations (3.10.1)
60
+ diff-lcs (>= 1.2.0, < 2.0)
61
+ rspec-support (~> 3.10.0)
62
+ rspec-mocks (3.10.2)
63
+ diff-lcs (>= 1.2.0, < 2.0)
64
+ rspec-support (~> 3.10.0)
65
+ rspec-support (3.10.2)
66
+ rubocop (1.11.0)
67
+ parallel (~> 1.10)
68
+ parser (>= 3.0.0.0)
69
+ rainbow (>= 2.2.2, < 4.0)
70
+ regexp_parser (>= 1.8, < 3.0)
71
+ rexml
72
+ rubocop-ast (>= 1.2.0, < 2.0)
73
+ ruby-progressbar (~> 1.7)
74
+ unicode-display_width (>= 1.4.0, < 3.0)
75
+ rubocop-ast (1.4.1)
76
+ parser (>= 2.7.1.5)
77
+ rubocop-config-umbrellio (1.11.0.40)
78
+ rubocop (= 1.11.0)
79
+ rubocop-performance (= 1.10.0)
80
+ rubocop-rails (= 2.9.1)
81
+ rubocop-rake (= 0.5.1)
82
+ rubocop-rspec (= 2.2.0)
83
+ rubocop-sequel (= 0.2.0)
84
+ rubocop-performance (1.10.0)
85
+ rubocop (>= 0.90.0, < 2.0)
86
+ rubocop-ast (>= 0.4.0)
87
+ rubocop-rails (2.9.1)
88
+ activesupport (>= 4.2.0)
89
+ rack (>= 1.1)
90
+ rubocop (>= 0.90.0, < 2.0)
91
+ rubocop-rake (0.5.1)
92
+ rubocop
93
+ rubocop-rspec (2.2.0)
94
+ rubocop (~> 1.0)
95
+ rubocop-ast (>= 1.1.0)
96
+ rubocop-sequel (0.2.0)
97
+ rubocop (~> 1.0)
98
+ ruby-progressbar (1.11.0)
99
+ ruby2_keywords (0.0.5)
100
+ sequel (5.43.0)
101
+ simplecov (0.21.2)
102
+ docile (~> 1.1)
103
+ simplecov-html (~> 0.11)
104
+ simplecov_json_formatter (~> 0.1)
105
+ simplecov-html (0.12.3)
106
+ simplecov-lcov (0.8.0)
107
+ simplecov_json_formatter (0.1.2)
108
+ symbiont-ruby (0.6.0)
109
+ thor (1.1.0)
110
+ tzinfo (2.0.4)
111
+ concurrent-ruby (~> 1.0)
112
+ umbrellio-sequel-plugins (0.4.0.164)
113
+ sequel
114
+ symbiont-ruby (>= 0.6)
115
+ unicode-display_width (2.0.0)
116
+ yard (0.9.26)
117
+ zeitwerk (2.4.2)
118
+
119
+ PLATFORMS
120
+ x86_64-darwin-20
121
+ x86_64-linux
122
+
123
+ DEPENDENCIES
124
+ activesupport
125
+ bundler
126
+ bundler-audit
127
+ ci-helper
128
+ nokogiri
129
+ nori
130
+ pry
131
+ rake
132
+ rspec
133
+ rubocop-config-umbrellio
134
+ simplecov
135
+ simplecov-lcov
136
+ umbrellio-utils!
137
+ yard
138
+
139
+ BUNDLED WITH
140
+ 2.2.22
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
 
@@ -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
 
@@ -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,50 @@ module UmbrellioUtils
60
60
  def to_date_part_string(part)
61
61
  format("%<part>02d", part: part)
62
62
  end
63
+
64
+ #
65
+ # Expands a hash whose keys contain the path.
66
+ #
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
+ # Defaults to :to_sym
71
+ #
72
+ # @return [Hash] expanded hash
73
+ #
74
+ def expand_hash(hash, delimiter: ".", key_converter: :to_sym)
75
+ result = hash.each_with_object(Misc.build_infinite_hash) do |entry, memo|
76
+ path, value = entry
77
+ *path_to_key, key = path.to_s.split(delimiter).map(&key_converter)
78
+
79
+ if path_to_key.empty?
80
+ memo[key] = value
81
+ else
82
+ resolved_hash = memo.dig(*path_to_key)
83
+ resolved_hash[key] = value
84
+ end
85
+ end
86
+
87
+ Misc.reset_defaults_for_hash(result)
88
+ end
89
+
90
+ #
91
+ # Expands a nested hash whose keys contain the path.
92
+ #
93
+ # @param hash [Hash] hash which you want to expand
94
+ # @param **expand_hash_options [Hash] options, that the
95
+ # {#expand_hash} method accepts
96
+ #
97
+ # @return [Hash] expanded hash
98
+ #
99
+ def deeply_expand_hash(hash, **expand_hash_options)
100
+ transformed_hash = hash.transform_values do |value|
101
+ next deeply_expand_hash(value, **expand_hash_options) if value.is_a?(Hash)
102
+
103
+ value
104
+ end
105
+
106
+ expand_hash(transformed_hash, **expand_hash_options)
107
+ end
63
108
  end
64
109
  end
@@ -19,10 +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
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
+ #
42
+ def build_infinite_hash
43
+ Hash.new { |hash, key| hash[key] = Hash.new(&hash.default_proc) }
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
27
65
  end
28
66
  end
@@ -21,7 +21,7 @@ module UmbrellioUtils
21
21
  xml.xpath("//@*").remove if remove_attributes
22
22
 
23
23
  tags_converter = snakecase ? -> (tag) { tag.snakecase.to_sym } : -> (tag) { tag.to_sym }
24
- nori = Nori.new(convert_tags_to: tags_converter)
24
+ nori = Nori.new(convert_tags_to: tags_converter, convert_dashes_to_underscores: false)
25
25
  nori.parse(xml.to_xml(save_with: Nokogiri::XML::Node::SaveOptions::NO_DECLARATION))
26
26
  end
27
27
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module UmbrellioUtils
4
- VERSION = "0.1.0"
4
+ VERSION = "0.3.2"
5
5
  end
@@ -16,6 +16,7 @@ Gem::Specification.new do |spec|
16
16
 
17
17
  spec.metadata["homepage_uri"] = spec.homepage
18
18
  spec.metadata["source_code_uri"] = "https://github.com/umbrellio/utils"
19
+ spec.metadata["documentation_uri"] = "https://rubydoc.info/gems/umbrellio-utils"
19
20
 
20
21
  # Specify which files should be added to the gem when it is released.
21
22
  # The `git ls-files -z` loads the files in the RubyGem that have been added into git.
@@ -26,15 +27,19 @@ Gem::Specification.new do |spec|
26
27
  spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
27
28
  spec.require_paths = ["lib"]
28
29
 
29
- spec.add_dependency "memery"
30
+ spec.add_dependency "memery", "~> 1"
30
31
 
32
+ spec.add_development_dependency "activesupport"
31
33
  spec.add_development_dependency "bundler"
32
34
  spec.add_development_dependency "bundler-audit"
33
35
  spec.add_development_dependency "ci-helper"
36
+ spec.add_development_dependency "nokogiri"
37
+ spec.add_development_dependency "nori"
34
38
  spec.add_development_dependency "pry"
35
39
  spec.add_development_dependency "rake"
36
40
  spec.add_development_dependency "rspec"
37
41
  spec.add_development_dependency "rubocop-config-umbrellio"
38
42
  spec.add_development_dependency "simplecov"
39
43
  spec.add_development_dependency "simplecov-lcov"
44
+ spec.add_development_dependency "yard"
40
45
  end
metadata CHANGED
@@ -1,23 +1,37 @@
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.3.2
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-08-09 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: memery
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1'
27
+ - !ruby/object:Gem::Dependency
28
+ name: activesupport
15
29
  requirement: !ruby/object:Gem::Requirement
16
30
  requirements:
17
31
  - - ">="
18
32
  - !ruby/object:Gem::Version
19
33
  version: '0'
20
- type: :runtime
34
+ type: :development
21
35
  prerelease: false
22
36
  version_requirements: !ruby/object:Gem::Requirement
23
37
  requirements:
@@ -66,6 +80,34 @@ dependencies:
66
80
  - - ">="
67
81
  - !ruby/object:Gem::Version
68
82
  version: '0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: nokogiri
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: nori
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
69
111
  - !ruby/object:Gem::Dependency
70
112
  name: pry
71
113
  requirement: !ruby/object:Gem::Requirement
@@ -150,6 +192,20 @@ dependencies:
150
192
  - - ">="
151
193
  - !ruby/object:Gem::Version
152
194
  version: '0'
195
+ - !ruby/object:Gem::Dependency
196
+ name: yard
197
+ requirement: !ruby/object:Gem::Requirement
198
+ requirements:
199
+ - - ">="
200
+ - !ruby/object:Gem::Version
201
+ version: '0'
202
+ type: :development
203
+ prerelease: false
204
+ version_requirements: !ruby/object:Gem::Requirement
205
+ requirements:
206
+ - - ">="
207
+ - !ruby/object:Gem::Version
208
+ version: '0'
153
209
  description: UmbrellioUtils is collection of utility classes and helpers
154
210
  email:
155
211
  - VanyaZ158@gmail.com
@@ -157,11 +213,13 @@ executables: []
157
213
  extensions: []
158
214
  extra_rdoc_files: []
159
215
  files:
216
+ - ".editorconfig"
160
217
  - ".github/workflows/test.yml"
161
218
  - ".gitignore"
162
219
  - ".rspec"
163
220
  - ".rubocop.yml"
164
221
  - Gemfile
222
+ - Gemfile.lock
165
223
  - LICENSE.txt
166
224
  - README.md
167
225
  - Rakefile
@@ -192,6 +250,7 @@ licenses:
192
250
  metadata:
193
251
  homepage_uri: https://github.com/umbrellio/utils
194
252
  source_code_uri: https://github.com/umbrellio/utils
253
+ documentation_uri: https://rubydoc.info/gems/umbrellio-utils
195
254
  post_install_message:
196
255
  rdoc_options: []
197
256
  require_paths:
@@ -207,7 +266,7 @@ required_rubygems_version: !ruby/object:Gem::Requirement
207
266
  - !ruby/object:Gem::Version
208
267
  version: '0'
209
268
  requirements: []
210
- rubygems_version: 3.2.15
269
+ rubygems_version: 3.2.22
211
270
  signing_key:
212
271
  specification_version: 4
213
272
  summary: A set of utilities that speed up development