denormalize_fields 1.0.1 → 1.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: 0236da61bb8d620a30c1d80b5e2915655c3fa172209e48e4a0574319bab02318
4
- data.tar.gz: 186179fca7937e35b792f44d859c58febe38bdc28c1ea7e41b347a7280919d02
3
+ metadata.gz: ebcb93fe9e4bebedb99005eb92bb625eeba3361de0f635db52a892d367edfc28
4
+ data.tar.gz: 7305577482c40ce270a86e265821c105538162e971082d6512e58008a84055d7
5
5
  SHA512:
6
- metadata.gz: 18db814fcaaa2e8a8c9dcf48469ab6e464a231157d5e5c8cd23293b8c11279df911ccd591536aab593b3ab9e2507bb87db5ed7de55228cea99434d201c9d53be
7
- data.tar.gz: 302b99956194d9fd94c47fa60a9aa5198b82fe7052b74f88fcdd87dc8945dd2c44644b217e6c81738df55c71f35804c98f3f4646c940b56a5195ab9cce680af3
6
+ metadata.gz: 6a7804de435350d740ecbbe773a1d09ec75f3bf15164cb0d27ed58821e8d4d7a195aa449c6208cb680b31ae91bfa0959efd0b2d60c015fe8e63bf7c9ce27b197
7
+ data.tar.gz: 5e16fce7610a2909ab07948a765b566f2cc4f9e2bb09b7792ee6928b64dfc3cc6d462e229dd5226c11ab6ae76651c1ef58528589e7315477267cb1c100272d63
@@ -33,8 +33,22 @@ module DenormalizeFields
33
33
  end
34
34
 
35
35
  def changeset(record:, mapping:)
36
- record.saved_changes.slice(*mapping.keys).each.with_object({}) do |(k, v), a|
37
- a[mapping.fetch(k.to_sym)] = v.last
36
+ keys = mapping.keys.flatten
37
+ record.saved_changes.slice(*keys).each.with_object({}) do |(k, v), acc|
38
+ changed_field = k.to_sym
39
+ new_value = v.last
40
+
41
+ mapping.each do |source, dest|
42
+ if source.is_a?(Array) && source.include?(changed_field)
43
+ if acc.key?(dest)
44
+ acc[dest] += " #{new_value}"
45
+ else
46
+ acc[dest] = new_value.to_s
47
+ end
48
+ elsif source == changed_field
49
+ acc[dest] = new_value
50
+ end
51
+ end
38
52
  end
39
53
  end
40
54
 
@@ -1,3 +1,3 @@
1
1
  module DenormalizeFields
2
- VERSION = '1.0.1'
2
+ VERSION = '1.1.0'
3
3
  end
metadata CHANGED
@@ -1,14 +1,14 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: denormalize_fields
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.0.1
4
+ version: 1.1.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janosch Müller
8
8
  autorequire:
9
9
  bindir: bin
10
10
  cert_chain: []
11
- date: 2020-02-13 00:00:00.000000000 Z
11
+ date: 2020-03-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: activerecord