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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA256:
3
- metadata.gz: ebcb93fe9e4bebedb99005eb92bb625eeba3361de0f635db52a892d367edfc28
4
- data.tar.gz: 7305577482c40ce270a86e265821c105538162e971082d6512e58008a84055d7
3
+ metadata.gz: 7bf731da26d483667dbb6a1942755bdf5c6cf5161aaf1b2d9fb1b2dc84366d96
4
+ data.tar.gz: a8e09ec6ced26720d404ca8e693f1e9c036a92b01b9f7d607b8cb6a51587112f
5
5
  SHA512:
6
- metadata.gz: 6a7804de435350d740ecbbe773a1d09ec75f3bf15164cb0d27ed58821e8d4d7a195aa449c6208cb680b31ae91bfa0959efd0b2d60c015fe8e63bf7c9ce27b197
7
- data.tar.gz: 5e16fce7610a2909ab07948a765b566f2cc4f9e2bb09b7792ee6928b64dfc3cc6d462e229dd5226c11ab6ae76651c1ef58528589e7315477267cb1c100272d63
6
+ metadata.gz: d3cb5a23f3896d6074020c48e53b954f0e4266a779da1b7c106d8bc5d0df6f22597bcab869ef9872d14aa23de163aa5b6d2df1e7904ac66a190d9546b462d462
7
+ data.tar.gz: 75c819d17a023f5fbbade955cb90ee54417e4a22807ab78fb924aff011611bf4d858fbf7cfad1eb63bbf9fe2807f0897c6d89a0be87cde2902757bf08266fbdb
@@ -33,21 +33,14 @@ module DenormalizeFields
33
33
  end
34
34
 
35
35
  def changeset(record:, mapping:)
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
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
@@ -1,3 +1,3 @@
1
1
  module DenormalizeFields
2
- VERSION = '1.1.0'
2
+ VERSION = '1.1.1'
3
3
  end
metadata CHANGED
@@ -1,7 +1,7 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: denormalize_fields
3
3
  version: !ruby/object:Gem::Version
4
- version: 1.1.0
4
+ version: 1.1.1
5
5
  platform: ruby
6
6
  authors:
7
7
  - Janosch Müller