From 5c9a7b134d7871a2c1c4cc48a954503ab301057e Mon Sep 17 00:00:00 2001 From: IJ Kim Date: Sat, 2 Jul 2022 09:45:56 -0400 Subject: [PATCH] Sf.client.query('select ') returns nil instead of [] now, so added line to return [] when the query result is nil --- lib/sf/account.rb | 6 +++--- lib/sf/base.rb | 2 +- lib/sf/contact.rb | 2 +- lib/sf/contact_affiliation.rb | 2 +- lib/sf/opportunity.rb | 6 +++--- lib/sf/presenter.rb | 2 +- lib/sf/reg_event.rb | 4 ++-- lib/sf/reg_meeting.rb | 2 +- lib/sf/reg_option.rb | 2 +- lib/sf/reg_rate.rb | 2 +- lib/sf/reg_registration.rb | 5 +++-- lib/sf/service_institution.rb | 2 +- lib/sf/session.rb | 8 ++++---- lib/sf/sponsorship.rb | 2 +- lib/sf/version.rb | 2 +- 15 files changed, 25 insertions(+), 24 deletions(-) diff --git a/lib/sf/account.rb b/lib/sf/account.rb index 5e1cef0..e0e57a6 100644 --- a/lib/sf/account.rb +++ b/lib/sf/account.rb @@ -129,7 +129,7 @@ def self.active_inc_parts(service_name) and (Service_End_Date__c = null or Service_End_Date__c > #{today}) and (Service_Start_Date__c = null or Service_Start_Date__c < #{today}) and Do_Not_Publish__c <> true") - build_collection sobjects.map(&:Supporting_Institution__r) unless sobjects.blank? + sobjects.blank? ? [] : build_collection(sobjects.map(&:Supporting_Institution__r)) end def self.cert_service_subscribers @@ -143,7 +143,7 @@ def self.cert_service_subscribers and Service_End_Date__c = null and (Type_of_Support__c = 'Subscriber' or Type_of_Support__c = 'subscriber_parent') and Do_Not_Publish__c <> true") - build_collection sobjects.map(&:Supporting_Institution__r) unless sobjects.blank? + sobjects.blank? ? [] : build_collection(sobjects.map(&:Supporting_Institution__r)) end private @@ -156,7 +156,7 @@ def subscriptions # The latest subscription is included only in case of the multiple subscriptions of the same service. def start_dates_by_subscription start_dates = {} - subscriptions.each { |s| start_dates[s.Service__r.Name] = s.Service_Start_Date__c } + subscriptions&.each { |s| start_dates[s.Service__r.Name] = s.Service_Start_Date__c } start_dates end end diff --git a/lib/sf/base.rb b/lib/sf/base.rb index a7ef6dc..b286c46 100644 --- a/lib/sf/base.rb +++ b/lib/sf/base.rb @@ -42,7 +42,7 @@ def find_by(args = {}) def where(args = {}) where = args.map { |k, v| "#{k} = \'#{v}\'" }.join(' and ') sobjects = Sf.client.query("select Id, Name from #{class_name} where #{where}") - build_collection sobjects unless sobjects.blank? + sobjects.blank? ? [] : build_collection(sobjects) end end end diff --git a/lib/sf/contact.rb b/lib/sf/contact.rb index 9bccb5a..824f56b 100644 --- a/lib/sf/contact.rb +++ b/lib/sf/contact.rb @@ -113,7 +113,7 @@ def self.find(id) def self.where(args = {}) where = args.map { |k, v| "#{k} = \'#{v}\'" }.join(' and ') sobjects = Sf.client.query("select #{FIELDS_SELECT_STR} from Contact where #{where}") - build_collection sobjects unless sobjects.blank? + sobjects.blank? ? [] : build_collection(sobjects) end def self.find_by(args = {}) diff --git a/lib/sf/contact_affiliation.rb b/lib/sf/contact_affiliation.rb index 219a859..cb0ab2f 100644 --- a/lib/sf/contact_affiliation.rb +++ b/lib/sf/contact_affiliation.rb @@ -35,7 +35,7 @@ def respond_to_missing?(method_name, include_private = false) def self.where(args = {}) where = args.map { |k, v| "#{k} = \'#{v}\'" }.join(' and ') sobjects = Sf.client.query("select #{FIELDS_SELECT_STR} from #{API_NAME} where #{where}") - build_collection sobjects unless sobjects.blank? + sobjects.blank? ? [] : build_collection(sobjects) end end end diff --git a/lib/sf/opportunity.rb b/lib/sf/opportunity.rb index 56f9a70..52d7767 100644 --- a/lib/sf/opportunity.rb +++ b/lib/sf/opportunity.rb @@ -33,20 +33,20 @@ def self.inc_participations(since_date = nil) since_date ||= Date.today since = since_date.to_date.to_s sobjects = Sf.client.query("select #{FIELDS_SELECT_STR} from Opportunity where Name like '%InCommon Participation%' and IsWon = true and CloseDate >= #{since}") - build_collection sobjects unless sobjects.blank? + sobjects.blank? ? [] : build_collection(sobjects) end def self.cert_subscribers(since_date = nil) since_date ||= Date.today since = since_date.to_date.to_s sobjects = Sf.client.query("select #{FIELDS_SELECT_STR} from Opportunity where Name like '%Certificate Service%' and (not Type like '%Existing Business%') and IsWon = true and CloseDate >= #{since}") - build_collection sobjects unless sobjects.blank? + sobjects.blank? ? [] : build_collection(sobjects) end def self.eduroam_opportunities stages = "('Closed Won', 'Negotiation/Review', 'Transferred Internally', 'Proposal/Price Quote', 'Prospecting')" sobjects = Sf.client.query("select #{FIELDS_SELECT_STR}, Account.Name from Opportunity where Name like '%Trust and Identity - eduroam%' and StageName in #{stages}") - build_collection sobjects unless sobjects.blank? + sobjects.blank? ? [] : build_collection(sobjects) end # stages diff --git a/lib/sf/presenter.rb b/lib/sf/presenter.rb index 17f3b56..52973f4 100644 --- a/lib/sf/presenter.rb +++ b/lib/sf/presenter.rb @@ -20,7 +20,7 @@ def respond_to_missing?(method_name, include_private = false) def where(args = {}) where = args.map { |k, v| "#{k} = \'#{v}\'" }.join(' and ') sobjects = Sf.client.query("select Id, Name, cms_presenter_id__c from #{class_name} where #{where}") - build_collection sobjects unless sobjects.blank? + sobjects.blank? ? [] : build_collection(sobjects) end end end diff --git a/lib/sf/reg_event.rb b/lib/sf/reg_event.rb index 1a274bc..1e73db4 100644 --- a/lib/sf/reg_event.rb +++ b/lib/sf/reg_event.rb @@ -39,13 +39,13 @@ def self.find_by_code(code) def self.where(args = {}) where = args.map { |k, v| "#{k} = \'#{v}\'" }.join(' and ') sobjects = Sf.client.query("select #{FIELDS_SELECT_STR} from RegEvent__c where #{where}") - build_collection sobjects unless sobjects.blank? + sobjects.blank? ? [] : build_collection(sobjects) end def self.by_codes(codes = []) where = codes.map { |code| "code__c = \'#{code}\'" }.join(' or ') sobjects = Sf.client.query("select #{FIELDS_SELECT_STR} from RegEvent__c where #{where}") - build_collection sobjects unless sobjects.blank? + sobjects.blank? ? [] : build_collection(sobjects) end def self.create_from_event(event) diff --git a/lib/sf/reg_meeting.rb b/lib/sf/reg_meeting.rb index 3093304..ab0bedd 100644 --- a/lib/sf/reg_meeting.rb +++ b/lib/sf/reg_meeting.rb @@ -41,7 +41,7 @@ def self.find_all_by_event_id(event_id) def self.where(args = {}) where = args.map { |k, v| "#{k} = \'#{v}\'" }.join(' and ') sobjects = Sf.client.query("select Id, Name from RegMeeting__c where #{where}") - build_collection sobjects unless sobjects.blank? + sobjects.blank? ? [] : build_collection(sobjects) end end end diff --git a/lib/sf/reg_option.rb b/lib/sf/reg_option.rb index 911143e..c67ff01 100644 --- a/lib/sf/reg_option.rb +++ b/lib/sf/reg_option.rb @@ -50,7 +50,7 @@ def self.find_all_by_event_id(event_id) def self.where(args = {}) where = args.map { |k, v| "#{k} = \'#{v}\'" }.join(' and ') sobjects = Sf.client.query("select Id, Name from RegOption__c where #{where}") - build_collection sobjects unless sobjects.blank? + sobjects.blank? ? [] : build_collection(sobjects) end end end diff --git a/lib/sf/reg_rate.rb b/lib/sf/reg_rate.rb index 3258e17..c8a608c 100644 --- a/lib/sf/reg_rate.rb +++ b/lib/sf/reg_rate.rb @@ -41,7 +41,7 @@ def self.find_all_by_meeting_id(meeting_id) def self.where(args = {}) where = args.map { |k, v| "#{k} = \'#{v}\'" }.join(' and ') sobjects = Sf.client.query("select Id, Name from RegRate__c where #{where}") - build_collection sobjects unless sobjects.blank? + sobjects.blank? ? [] : build_collection(sobjects) end end end diff --git a/lib/sf/reg_registration.rb b/lib/sf/reg_registration.rb index e65c399..1e1599e 100644 --- a/lib/sf/reg_registration.rb +++ b/lib/sf/reg_registration.rb @@ -173,12 +173,12 @@ def self.order_by(args = {}) def self.query_with_reg_item_codes(where_stmt, order_stmt) reg_item_select = 'select code__c, reg_rate_code__c from reg_items__r' sobjects = Sf.client.query("select Id, #{FIELDS_SELECT_STR}, (#{reg_item_select}) from RegRegistration__c where #{where_stmt} #{order_stmt}") - build_collection sobjects unless sobjects.blank? + sobjects.blank? ? [] : build_collection(sobjects) end def self.query(where_stmt, order_stmt) sobjects = Sf.client.query("select Id, #{FIELDS_SELECT_STR} from RegRegistration__c where #{where_stmt} #{order_stmt}") - build_collection sobjects unless sobjects.blank? + sobjects.blank? ? [] : build_collection(sobjects) end def self.attendees_for(event_code, reg_item_code) @@ -189,6 +189,7 @@ def self.attendees_for(event_code, reg_item_code) where = "code__c = \'#{reg_item_code}\' and #{rr}.event_code__c = \'#{event_code}\'" sobjects = Sf.client.query("select #{selects} from RegItem__c where #{where}") build_collection sobjects.map(&:reg_registration_id__r) unless sobjects.blank? + sobjects.blank? ? [] : build_collection(sobjects.map(&:reg_registration_id__r)) end def self.roster_for(event_code, reg_item_code) diff --git a/lib/sf/service_institution.rb b/lib/sf/service_institution.rb index b133199..edbe7a1 100644 --- a/lib/sf/service_institution.rb +++ b/lib/sf/service_institution.rb @@ -35,7 +35,7 @@ def self.find(id) def self.where(args = {}) where = args.map { |k, v| "#{k} = \'#{v}\'" }.join(' and ') sobjects = Sf.client.query("select #{FIELDS_SELECT_STR} from #{API_NAME} where #{where}") - build_collection sobjects unless sobjects.blank? + sobjects.blank? ? [] : build_collection(sobjects) end end end diff --git a/lib/sf/session.rb b/lib/sf/session.rb index d2a1060..a65af7a 100644 --- a/lib/sf/session.rb +++ b/lib/sf/session.rb @@ -84,14 +84,14 @@ def self.presenters_by_event_code(code) event = Sf::RegEvent.find_by(code__c: code) sobjects = Sf.client.query("select Id, cms_session_id__c, (select Id, contact_id__c from Event_Presenters__r) from EventSession__c where event__c = \'#{event.Id}\'") - build_collection sobjects unless sobjects.blank? + sobjects.blank? ? [] : build_collection(sobjects) end def self.track_presenters_by_event_code(code) event = Sf::RegEvent.find_by(code__c: code) sobjects = Sf.client.query("select Id, cms_session_id__c, session_type__r.Name, (select Id, contact_id__c from Event_Presenters__r) from EventSession__c where session_type__r.Name = 'Track Session' and event__c = \'#{event.Id}\'") - build_collection sobjects unless sobjects.blank? + sobjects.blank? ? [] : build_collection(sobjects) end def self.presenter_ids_by_event_code(code) @@ -117,7 +117,7 @@ def self.query(where_stmt) session_type__r.Name, start_time__c, room_id__r.Name, cms_session_id__c, timestamp__c, date__c, end_time__c, auto_publish__c, LastModifiedBy.Name from EventSession__c where #{where_stmt}") - build_collection sobjects unless sobjects.blank? + sobjects.blank? ? [] : build_collection(sobjects) end def self.where(args = {}) @@ -126,7 +126,7 @@ def self.where(args = {}) session_type__r.Name, start_time__c, room_id__r.Name, cms_session_id__c, timestamp__c, date__c, end_time__c, auto_publish__c from EventSession__c where #{where}") - build_collection sobjects unless sobjects.blank? + sobjects.blank? ? [] : build_collection(sobjects) end end end diff --git a/lib/sf/sponsorship.rb b/lib/sf/sponsorship.rb index bac56d2..b1f02ff 100644 --- a/lib/sf/sponsorship.rb +++ b/lib/sf/sponsorship.rb @@ -49,7 +49,7 @@ def self.where(args = {}) sobjects = Sf.client.query("select Id, event__c, contact__c, sponsor__c, logo_url__c, cms_sponsor_id__c, cms_sponsor_name__c, sponsorship_type__c from EventSponsorship__c where #{where}") - build_collection sobjects unless sobjects.blank? + sobjects.blank? ? [] : build_collection(sobjects) end end end diff --git a/lib/sf/version.rb b/lib/sf/version.rb index d0ee0c7..fcc936b 100644 --- a/lib/sf/version.rb +++ b/lib/sf/version.rb @@ -1,3 +1,3 @@ module Sf - VERSION = "0.1.67" + VERSION = "0.1.68" end