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 +4 -4
- data/lib/denormalize_fields.rb +16 -2
- data/lib/denormalize_fields/version.rb +1 -1
- 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: ebcb93fe9e4bebedb99005eb92bb625eeba3361de0f635db52a892d367edfc28
|
4
|
+
data.tar.gz: 7305577482c40ce270a86e265821c105538162e971082d6512e58008a84055d7
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: 6a7804de435350d740ecbbe773a1d09ec75f3bf15164cb0d27ed58821e8d4d7a195aa449c6208cb680b31ae91bfa0959efd0b2d60c015fe8e63bf7c9ce27b197
|
7
|
+
data.tar.gz: 5e16fce7610a2909ab07948a765b566f2cc4f9e2bb09b7792ee6928b64dfc3cc6d462e229dd5226c11ab6ae76651c1ef58528589e7315477267cb1c100272d63
|
data/lib/denormalize_fields.rb
CHANGED
@@ -33,8 +33,22 @@ module DenormalizeFields
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def changeset(record:, mapping:)
|
36
|
-
|
37
|
-
|
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
|
|
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
|
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-
|
11
|
+
date: 2020-03-26 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: activerecord
|