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 +4 -4
- data/CHANGELOG.md +8 -0
- data/Gemfile.lock +4 -1
- data/README.md +3 -0
- data/lib/hash_with_dot_access/version.rb +1 -1
- data/lib/hash_with_dot_access.rb +25 -0
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 3b297d95788d51c96fcf68f4ecf230b743831d21e0987f21ff162bbfcdfa5551
|
4
|
+
data.tar.gz: 43ebba540d1ddfdb4ebab7d80dbbdf52ab031ae5d6915982cdd3d558d80feb8a
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
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
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:
|
data/lib/hash_with_dot_access.rb
CHANGED
@@ -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.
|
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-
|
11
|
+
date: 2024-04-21 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|