active_serialize 2.4.0 → 2.4.2
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/lib/active_serialize.rb +7 -5
- data/lib/active_serialize/relation.rb +4 -4
- data/lib/active_serialize/version.rb +1 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: c37b91e388b4825a96e1054e39d9c3df6bf98a50
|
4
|
+
data.tar.gz: 37c32696a41aa300b79ab9119a9d5e697b71ff0d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 9f3b807ed104b10aeb173193cb34de6d6d4bf9255c6c790fdc3882694af04720187bd60e5e61d19ed1623b1cb153d15d317b8c425daf027edee5d44d87765cee
|
7
|
+
data.tar.gz: 788348b34876bdf18be7dbd59d02f081f88ad36ad9dbe10da56a1797d077ba47ddba65a2f8f575296cb1c080554f078f74c74c41b71084f8fa97e35bd43443ea
|
data/lib/active_serialize.rb
CHANGED
@@ -31,14 +31,16 @@ module ActiveSerialize
|
|
31
31
|
end
|
32
32
|
|
33
33
|
module ToH
|
34
|
-
def to_h(*groups, rmv: [ ], add: [ ], recursive: [ ], plucked: { }, merge: { })
|
35
|
-
|
36
|
-
|
34
|
+
def to_h(*groups, rmv: [ ], add: [ ], flat_add: [ ], recursive: [ ], plucked: { }, merge: { })
|
35
|
+
recursion = (_active_serialize[:recursive] + recursive).map { |k| [ k, public_send(k)&.to_ha(*groups) ] }.to_h
|
36
|
+
merge.merge!(flat_add.map(&method(:public_send)).reduce({ }, :merge)) if flat_add.present?
|
37
37
|
|
38
38
|
KeyFormatter.(_active_serialize[:key_format],
|
39
39
|
active_serialize_keys(*groups, rmv: rmv, add: add)
|
40
|
-
.map{ |key| [
|
41
|
-
.merge(plucked.merge(recursion).merge(merge)
|
40
|
+
.map { |key| [ key, public_send(key) ] }.to_h
|
41
|
+
.merge(plucked).merge(recursion).merge(merge)
|
42
|
+
.transform_keys { |key| _active_serialize[:map][key] || key }
|
43
|
+
.deep_stringify_keys!
|
42
44
|
)
|
43
45
|
end
|
44
46
|
|
@@ -2,20 +2,20 @@
|
|
2
2
|
|
3
3
|
module ActiveSerialize
|
4
4
|
module Relation
|
5
|
-
def to_ha(pluck: [ ], plucked: nil, **args)
|
5
|
+
def to_ha(*groups, pluck: [ ], plucked: nil, **args)
|
6
6
|
plucked ||=
|
7
7
|
if pluck.is_a?(Proc)
|
8
8
|
instance_eval(&pluck)
|
9
9
|
else
|
10
|
-
(_active_serialize[:pluck] + pluck).map { |key| [ key, instance_eval(&method(key)) ] }.to_h
|
10
|
+
(_active_serialize[:pluck] + pluck).uniq.map { |key| [ key, instance_eval(&method(key)) ] }.to_h
|
11
11
|
end
|
12
12
|
|
13
13
|
if plucked.present?
|
14
14
|
each_with_index.map do |record, i|
|
15
|
-
record.to_h(plucked: plucked.each_key.map { |k| [ k, plucked[k][i] ] }.to_h, **args)
|
15
|
+
record.to_h(*groups, plucked: plucked.each_key.map { |k| [ k, plucked[k][i] ] }.to_h, **args)
|
16
16
|
end
|
17
17
|
else
|
18
|
-
map { |record| record.to_h(**args) }
|
18
|
+
map { |record| record.to_h(*groups, **args) }
|
19
19
|
end
|
20
20
|
end
|
21
21
|
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: active_serialize
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 2.4.
|
4
|
+
version: 2.4.2
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zhandao
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-
|
11
|
+
date: 2019-04-24 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|