hash_with_dot_access 2.0.0 → 2.1.0

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: be6e40c79e1f2c6148e84b6ef6b3521d9c07500bac9603f793a39dac7b3278ce
4
+ data.tar.gz: ace5ebdd3d951858e6dda87a96cfb9301b4ce7dc9802184cdee1cbd69e664538
5
5
  SHA512:
6
- metadata.gz: 544048deb5346dbf49460f66e32e546d4fd31532cac0fc00d89def4aee03101473295a58b77bea39d8aab5f5cfe4ecdf892c806e32493c1e560cde08f3a51776
7
- data.tar.gz: 46c68788e0b6edf892d3d5d26a7f6b7a7c1504d553e9275e48f083cf051d5264d57cf7226cfd593b640eb7aebddc3b96e426d61de159d0f4ee874b219ff39ef2
6
+ metadata.gz: 8763ae8a9cd9aec38d1cf2c4e0d659824633295576dfc3132968b82d848f92e354e5fb417f182b5b9be32ba8e2276996e3f36a2e3b8ce71de404c817cd599f1f
7
+ data.tar.gz: 8ee6d9ba1bdbc2322c40c1a4c79136d43c94376ec167f334123e17844cde1e9364a6a8bee75573827704a12152f328a55bf86980ab249c4170fac9482caa043e
data/CHANGELOG.md CHANGED
@@ -1,5 +1,9 @@
1
1
  # Changelog
2
2
 
3
+ ## [2.1.0] - 2024-04-20
4
+
5
+ - Adds conversion back to a hash with `to_h` and `to_dot_h` for enumeration.
6
+
3
7
  ## [2.0.0] - 2024-04-20
4
8
 
5
9
  - 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.0)
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.0"
3
3
  end
@@ -13,6 +13,18 @@ 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 = value.dup if value.frozen?
23
+ value.map! { primitive_value(_1) }
24
+ else
25
+ value
26
+ end
27
+ end
16
28
  end
17
29
 
18
30
  class Hash < ::Hash
@@ -138,6 +150,20 @@ module HashWithDotAccess
138
150
  def compact
139
151
  dup.tap { _1.compact! }
140
152
  end
153
+
154
+ alias_method :_to_h, :to_h
155
+
156
+ def to_dot_h(...)
157
+ self.class.new _to_h(...)
158
+ end
159
+
160
+ def to_h
161
+ ::Hash.new.update(self).to_h do |k, v|
162
+ value = Utils.primitive_value(v)
163
+ k, value = yield k, value if block_given?
164
+ [k, value]
165
+ end
166
+ end
141
167
  end
142
168
 
143
169
  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.0
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