From 849228a08a4e2fde30f97676919477e16b2fac7c Mon Sep 17 00:00:00 2001 From: IJ Kim Date: Thu, 17 Jan 2019 21:23:41 -0500 Subject: [PATCH] check if attrs exist before comparing and stop pre-populating the instant variable Sf::Contact#diffs --- lib/sf/contact.rb | 24 ++++++++++++++---------- 1 file changed, 14 insertions(+), 10 deletions(-) diff --git a/lib/sf/contact.rb b/lib/sf/contact.rb index f17880a..9287a76 100644 --- a/lib/sf/contact.rb +++ b/lib/sf/contact.rb @@ -46,16 +46,7 @@ def set_person_by_email(email) end def get_diffs - unless self.Id.nil? - sf_person_mapping.each do |p, sf| - diffs[p.to_sym] = true unless self.send(sf).eql? person.send(p) - end - else - sf_person_mapping.each do |p, sf| - diffs[p.to_sym] = true - end - end - diffs + self.Id.nil? ? flag_all_attrbutes_as_diff : flag_attributes_if_different end def attrs_from_person @@ -199,4 +190,17 @@ def self.build_contacts(from, where) IN (SELECT Contact__c FROM #{from} where #{where})" ) end + + def flag_all_attrbutes_as_diff + sf_person_mapping.merge(sf_person_mapping) do |p, sf| + true if person.respond_to?(p) + end.compact + end + + def flag_attributes_if_different + sf_person_mapping.merge(sf_person_mapping) do |p, sf| + true if person.respond_to?(p) and !self.send(sf).eql?(person.send(p)) + end.compact + end + end