denormalize_fields 1.1.0 → 1.1.1
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 +7 -14
- data/lib/denormalize_fields/version.rb +1 -1
- metadata +1 -1
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA256:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 7bf731da26d483667dbb6a1942755bdf5c6cf5161aaf1b2d9fb1b2dc84366d96
|
4
|
+
data.tar.gz: a8e09ec6ced26720d404ca8e693f1e9c036a92b01b9f7d607b8cb6a51587112f
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: d3cb5a23f3896d6074020c48e53b954f0e4266a779da1b7c106d8bc5d0df6f22597bcab869ef9872d14aa23de163aa5b6d2df1e7904ac66a190d9546b462d462
|
7
|
+
data.tar.gz: 75c819d17a023f5fbbade955cb90ee54417e4a22807ab78fb924aff011611bf4d858fbf7cfad1eb63bbf9fe2807f0897c6d89a0be87cde2902757bf08266fbdb
|
data/lib/denormalize_fields.rb
CHANGED
@@ -33,21 +33,14 @@ module DenormalizeFields
|
|
33
33
|
end
|
34
34
|
|
35
35
|
def changeset(record:, mapping:)
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
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
|
36
|
+
mapping.each.with_object({}) do |(source, dest), hash|
|
37
|
+
if source.is_a?(Array)
|
38
|
+
if source.any? { |field| record.saved_change_to_attribute?(field) }
|
39
|
+
current_values = record.attributes.values_at(*source.map(&:to_s))
|
40
|
+
hash[dest] = current_values.join(' ')
|
50
41
|
end
|
42
|
+
elsif change = record.saved_change_to_attribute(source)
|
43
|
+
hash[dest] = change.last
|
51
44
|
end
|
52
45
|
end
|
53
46
|
end
|