ruby-rails-extensions 2.1.0.pre.rc.1 → 2.1.0.pre.rc.3

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: 9db5274566aa11b9d201cbb888567d1decc0cf37d66da0f97bc0d537ea7eb9dd
4
- data.tar.gz: 926d3931774ec62898dee45d6497cf4f3583a2644b932a498e3c4be80712874b
3
+ metadata.gz: 0e50d84a162aacc2d390f3c614cbb90eb1ca0dcd300af71f113a90ef32957fa9
4
+ data.tar.gz: 1fab75f93d14b9fe573bab13b501a5c02392b8cda2dc9d71ebd249b0d0127236
5
5
  SHA512:
6
- metadata.gz: a68d1a5f5fef8be14e6d4f22b4a7708a271d2a693eeabdb270d9c92c11676af3b545fd58e1e18aac160db13f99c1d15979cc3aeaa8e182406a86cd675474240f
7
- data.tar.gz: 8ee76aa134472fb34140a596c17ebe79dbf198d0bcc75aa942ed5270adad2a0a57c27ce3c3e021976be9d2d1104c97b1b20285aadcc6116f63f04988a63fbbfe
6
+ metadata.gz: af0f9b3787dbc7e4cada77d4b4c00cbb2e4796a6c0886a0b60a6837bd37c215dbb5e084b6897a230bf1577c2795b9a4ccabab24f02080aa3d16f4485eafe26bd
7
+ data.tar.gz: 807ed07672397a877bfbede2eebd367dcc816a313e637f25f7e64146910385cbe18104c1ef2763fab20c218323c89ec0565772f3acf2f053a815a93645432129
data/CHANGELOG.md CHANGED
@@ -1,8 +1,13 @@
1
1
  Unreleased Changes
2
2
  ------------------
3
3
 
4
- * Module added:
5
- * `Hash.nmerge` and `Hash.nmerge!`
4
+ 2.1.0 (Unreleased)
5
+ ------------------
6
+
7
+ * Modules added:
8
+ * `Hash#nmerge` and `Hash#nmerge!`
9
+ * `Hash#left_deep_merge` and `Hash#left_deep_merge!`
10
+ * `Hash#invert_with_dups`
6
11
 
7
12
  2.0.1 (2024-07-29)
8
13
  ------------------
@@ -0,0 +1,23 @@
1
+ # frozen_string_literal: true
2
+
3
+ Hash.class_eval do
4
+ # Invert a hash keeping possible duplicate values.
5
+ # @see Hash#invert for more details or to use without keeping duplicates.
6
+ # @see https://stackoverflow.com/a/10989394/8806642 for source.
7
+ #
8
+ # @example
9
+ # h = {:a => 1, :b => 2, :c => 3, :d => 4, :z => 1}
10
+ # h.invert
11
+ # # => {1=>:z, 2=>:b, 3=>:c, 4=>:d}
12
+ # h.invert_with_dups
13
+ # # => {1=>[:a, :z], 2=>[:b], 3=>[:c], 4=>[:d]}
14
+ #
15
+ # @return [Hash]
16
+ #
17
+ def invert_with_dups
18
+ each_with_object({}) do |(key, value), out|
19
+ out[value] ||= []
20
+ out[value] << key
21
+ end
22
+ end
23
+ end
@@ -0,0 +1,26 @@
1
+ # frozen_string_literal: true
2
+
3
+ Hash.class_eval do
4
+ # Do a deep merge, but don't override the key-value pairs on the left.
5
+ #
6
+ # @param other_hash [Hash]
7
+ #
8
+ # @return [Hash]
9
+ #
10
+ def left_deep_merge!(other_hash, &block)
11
+ merge!(other_hash) do |key, this_val, other_val|
12
+ if this_val.is_a?(Hash) && other_hash.is_a?(Hash)
13
+ this_val.left_deep_merge(other_val, &block)
14
+ elsif block_given?
15
+ yield(key, this_val, other_val)
16
+ else
17
+ this_val.presence || other_val
18
+ end
19
+ end
20
+ end
21
+
22
+ # @see #left_deep_merge!
23
+ def left_deep_merge(other_hash, &block)
24
+ dup.left_deep_merge!(other_hash, &block)
25
+ end
26
+ end
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module RubyRailsExtensions
4
- VERSION = '2.1.0-rc.1'
4
+ VERSION = '2.1.0-rc.3'
5
5
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: ruby-rails-extensions
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.1.0.pre.rc.1
4
+ version: 2.1.0.pre.rc.3
5
5
  platform: ruby
6
6
  authors:
7
7
  - Brands Insurance
@@ -64,6 +64,8 @@ files:
64
64
  - lib/ruby-rails-extensions/extensions/humanize_symbol.rb
65
65
  - lib/ruby-rails-extensions/extensions/in_utc.rb
66
66
  - lib/ruby-rails-extensions/extensions/input.rb
67
+ - lib/ruby-rails-extensions/extensions/invert_with_dups.rb
68
+ - lib/ruby-rails-extensions/extensions/left_deep_merge.rb
67
69
  - lib/ruby-rails-extensions/extensions/month_and_year.rb
68
70
  - lib/ruby-rails-extensions/extensions/month_year.rb
69
71
  - lib/ruby-rails-extensions/extensions/nmerge.rb