active_serialize 2.4.2 → 2.5.0
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/class_methods.rb +4 -2
- data/lib/active_serialize/version.rb +1 -1
- data/lib/active_serialize.rb +9 -3
- 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: 367ae37d7d28d38e8b6ad1a449590ddb72b42a94
|
4
|
+
data.tar.gz: 527f9f6c0bbbb718aa4c88229088237918429465
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 0cea92163449a43f483e950a4df97bafbdcd351a2851cfe0cec9be18f6d7a18fc8c258e2f595d656ca65b170f61647b8ffbfc40bd1fd33973cd1d9f509643622
|
7
|
+
data.tar.gz: 2b9c1d407792742d64270a95c79bdda36690c5605cf3d00e05a2e80465ab644df05b8470cf67969ae56967435ba24087a6e33b69fd0a1673a415b004f7b000c8
|
@@ -28,10 +28,12 @@ module ActiveSerialize
|
|
28
28
|
_active_serialize[:map].merge! settings
|
29
29
|
end
|
30
30
|
|
31
|
-
def active_serialize_keys(*groups, rmv: [ ], add: [ ])
|
31
|
+
def active_serialize_keys(*groups, rmv: [ ], add: [ ], only: nil, **opts)
|
32
|
+
return only if only
|
32
33
|
_active_serialize[:final] ||= column_names.map(&:to_sym) - _active_serialize[:rmv] + _active_serialize[:add]
|
33
|
-
_active_serialize[:final] - Array(rmv) + Array(add) +
|
34
|
+
result = _active_serialize[:final] - Array(rmv) + Array(add) +
|
34
35
|
_active_serialize[:groups].values_at(*groups).flatten.compact.uniq
|
36
|
+
opts[:if] ? { normal: result, if: opts[:if] } : result
|
35
37
|
end
|
36
38
|
end
|
37
39
|
end
|
data/lib/active_serialize.rb
CHANGED
@@ -31,13 +31,19 @@ module ActiveSerialize
|
|
31
31
|
end
|
32
32
|
|
33
33
|
module ToH
|
34
|
-
def to_h(*groups, rmv: [ ], add: [ ], flat_add: [ ], recursive: [ ], plucked: { }, merge: { })
|
34
|
+
def to_h(*groups, rmv: [ ], add: [ ], flat_add: [ ], recursive: [ ], plucked: { }, merge: { }, **opts)
|
35
35
|
recursion = (_active_serialize[:recursive] + recursive).map { |k| [ k, public_send(k)&.to_ha(*groups) ] }.to_h
|
36
36
|
merge.merge!(flat_add.map(&method(:public_send)).reduce({ }, :merge)) if flat_add.present?
|
37
|
+
keys = active_serialize_keys(*groups, rmv: rmv, add: add, **opts)
|
38
|
+
if keys.is_a?(Hash) && instance_exec(&keys[:if].first)
|
39
|
+
keys = keys[:if].last[:only] ||
|
40
|
+
keys[:normal] + (keys[:if].last[:add] || [ ]) - (keys[:if].last[:rmv] || [ ])
|
41
|
+
else
|
42
|
+
keys = keys[:normal]
|
43
|
+
end
|
37
44
|
|
38
45
|
KeyFormatter.(_active_serialize[:key_format],
|
39
|
-
|
40
|
-
.map { |key| [ key, public_send(key) ] }.to_h
|
46
|
+
keys.map { |key| [ key, public_send(key) ] }.to_h
|
41
47
|
.merge(plucked).merge(recursion).merge(merge)
|
42
48
|
.transform_keys { |key| _active_serialize[:map][key] || key }
|
43
49
|
.deep_stringify_keys!
|
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
|
+
version: 2.5.0
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- zhandao
|
8
8
|
autorequire:
|
9
9
|
bindir: exe
|
10
10
|
cert_chain: []
|
11
|
-
date: 2019-04-
|
11
|
+
date: 2019-04-30 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|