hash_with_dot_access 2.0.0 → 2.1.1

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: 66ad7a8ba3e1aaadf2526e3642d8d9b43e86602da6498e29058caa132a107630
4
- data.tar.gz: 3225eff99492d25a661997ae4a20d95ea573c22aeb6ba6d41be8c28d4496372a
3
+ metadata.gz: 3b297d95788d51c96fcf68f4ecf230b743831d21e0987f21ff162bbfcdfa5551
4
+ data.tar.gz: 43ebba540d1ddfdb4ebab7d80dbbdf52ab031ae5d6915982cdd3d558d80feb8a
5
5
  SHA512:
6
- metadata.gz: 544048deb5346dbf49460f66e32e546d4fd31532cac0fc00d89def4aee03101473295a58b77bea39d8aab5f5cfe4ecdf892c806e32493c1e560cde08f3a51776
7
- data.tar.gz: 46c68788e0b6edf892d3d5d26a7f6b7a7c1504d553e9275e48f083cf051d5264d57cf7226cfd593b640eb7aebddc3b96e426d61de159d0f4ee874b219ff39ef2
6
+ metadata.gz: fd4bc088b83911837623ddba8a73ca41df654b826406b5a7a2b27e82615002d080bfaa01e8632bc7654664eb75fd843cea9c48c89a108e92fa55217f99ca14e1
7
+ data.tar.gz: ef702738180b02250c7c113dcacf8d3203ffa2ce334647ccb1fcc8e33197df2d7dc55eb3c070e922d77744c93eb9372b126bc433e3122957544e227e2ffc6119
data/CHANGELOG.md CHANGED
@@ -1,5 +1,13 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.1.1] - 2024-04-20
4
+
5
+ - Fix issue where `to_h` was incorrectly mutating arrays containing hashes
6
+
7
+ ## [2.1.0] - 2024-04-20
8
+
9
+ - Adds conversion back to a hash with `to_h` and `to_dot_h` for enumeration.
10
+
3
11
  ## [2.0.0] - 2024-04-20
4
12
 
5
13
  - Completely rewrite internals and remove Active Support as a dependency
data/Gemfile.lock CHANGED
@@ -1,7 +1,7 @@
1
1
  PATH
2
2
  remote: .
3
3
  specs:
4
- hash_with_dot_access (2.0.0)
4
+ hash_with_dot_access (2.1.1)
5
5
 
6
6
  GEM
7
7
  remote: https://rubygems.org/
@@ -15,3 +15,6 @@ DEPENDENCIES
15
15
  bundler
16
16
  hash_with_dot_access!
17
17
  rake (~> 13.0)
18
+
19
+ BUNDLED WITH
20
+ 2.5.6
data/README.md CHANGED
@@ -55,6 +55,9 @@ hsh.x
55
55
  # => 0
56
56
  ```
57
57
 
58
+ You can convert a `HashWithDotAccess::Hash` back to a regular Hash with `to_h`, which even works with
59
+ block enumeration. Or use `to_dot_h` as a `to_h`-like enumerator which preserves dot access.
60
+
58
61
  ## Installation
59
62
 
60
63
  Add this line to your application's Gemfile:
@@ -1,3 +1,3 @@
1
1
  module HashWithDotAccess
2
- VERSION = "2.0.0"
2
+ VERSION = "2.1.1"
3
3
  end
@@ -13,6 +13,17 @@ module HashWithDotAccess
13
13
  value
14
14
  end
15
15
  end
16
+
17
+ def self.primitive_value(value)
18
+ case value
19
+ when ::Hash
20
+ value.to_h
21
+ when Array
22
+ value.map { primitive_value(_1) }
23
+ else
24
+ value
25
+ end
26
+ end
16
27
  end
17
28
 
18
29
  class Hash < ::Hash
@@ -138,6 +149,20 @@ module HashWithDotAccess
138
149
  def compact
139
150
  dup.tap { _1.compact! }
140
151
  end
152
+
153
+ alias_method :_to_h, :to_h
154
+
155
+ def to_dot_h(...)
156
+ self.class.new _to_h(...)
157
+ end
158
+
159
+ def to_h
160
+ ::Hash.new.update(self).to_h do |k, v|
161
+ value = Utils.primitive_value(v)
162
+ k, value = yield k, value if block_given?
163
+ [k, value]
164
+ end
165
+ end
141
166
  end
142
167
 
143
168
  module Refinements
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: hash_with_dot_access
3
3
  version: !ruby/object:Gem::Version
4
- version: 2.0.0
4
+ version: 2.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Bridgetown Team
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2024-04-20 00:00:00.000000000 Z
11
+ date: 2024-04-21 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler