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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: 3d9b2859163166929c779368b00c17271635964c
4
- data.tar.gz: 6ecb6dc7d235f89b2e95eaf382c84b72cc6dfc0e
3
+ metadata.gz: c37b91e388b4825a96e1054e39d9c3df6bf98a50
4
+ data.tar.gz: 37c32696a41aa300b79ab9119a9d5e697b71ff0d
5
5
  SHA512:
6
- metadata.gz: 192b5263921799f1a0acaa837a006b780a9939572d67d8cf3cec783b549358bc122276776668f988f3cf8e5f1b186c8e21358608b85ff24ea6a0a8a551f321ed
7
- data.tar.gz: 8036dd8ceb1d21917b6e282c27fc512cce92e3717774d032e04eca05da97d206e2ad91eade924a250f7957d9224c90c93ef4126d2953ffcbc9b55c373642c9b5
6
+ metadata.gz: 9f3b807ed104b10aeb173193cb34de6d6d4bf9255c6c790fdc3882694af04720187bd60e5e61d19ed1623b1cb153d15d317b8c425daf027edee5d44d87765cee
7
+ data.tar.gz: 788348b34876bdf18be7dbd59d02f081f88ad36ad9dbe10da56a1797d077ba47ddba65a2f8f575296cb1c080554f078f74c74c41b71084f8fa97e35bd43443ea
@@ -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
- tran_key = ->(key) { (_active_serialize[:map][key] || key).to_s }
36
- recursion = (_active_serialize[:recursive] + recursive).map { |k| [ k, public_send(k)&.to_ha ] }.to_h
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| [ tran_key.(key), public_send(key) ] }.to_h
41
- .merge(plucked.merge(recursion).merge(merge).transform_keys(&tran_key))
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
 
@@ -1,5 +1,5 @@
1
1
  # frozen_string_literal: true
2
2
 
3
3
  module ActiveSerialize
4
- VERSION = '2.4.0'
4
+ VERSION = '2.4.2'
5
5
  end
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.0
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-03-25 00:00:00.000000000 Z
11
+ date: 2019-04-24 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler