lib/eco/api/microcases/preserve_policy_groups.rb in eco-helpers-2.7.24 vs lib/eco/api/microcases/preserve_policy_groups.rb in eco-helpers-2.7.25

- old
+ new

@@ -6,25 +6,25 @@ # 1. It only works if the original value of `policy_group_ids` was **not** empty # @param person [Ecoportal::API::V1::Person] the person we want to update, carrying the changes to be done. # @param options [Hash] the options. # @param keep_new [Boolean] tells if it should keep the new policy groups or get rid of them. # @return [String] the final value of `policy_group_ids`. - def preserve_policy_groups(person, options, keep_new: false) - if account = person.account - if account.as_update.key?("policy_group_ids") - if original = person.original_doc.dig("account", "policy_group_ids") - unless original.empty? - if keep_new - person.account.policy_group_ids += original - else - person.account.policy_group_ids = original - end - end - end + def preserve_policy_groups(person, _options, keep_new: false) + return unless (account = person.account) + + account.policy_group_ids.tap do + next unless account.as_update.key?("policy_group_ids") + next unless (original = person.original_doc.dig("account", "policy_group_ids")) + next if original.empty? + + if keep_new + person.account.policy_group_ids += original + else + person.account.policy_group_ids = original end + + return account.policy_group_ids end - person.account&.policy_group_ids end - end end end