Skip to content

Commit

Permalink
Enumerates over SERIALIZED_FIELDS explicitly rather than duck typing
Browse files Browse the repository at this point in the history
  • Loading branch information
afred committed Jun 11, 2024
1 parent b780e98 commit 0eb35a6
Showing 1 changed file with 8 additions and 3 deletions.
11 changes: 8 additions & 3 deletions app/transactions/ams/steps/create_aapb_admin_data.rb
Original file line number Diff line number Diff line change
Expand Up @@ -53,15 +53,20 @@ def save_aapb_admin_data(change_set)
def set_admin_data_attributes(admin_data, change_set)
AdminData.attributes_for_update.each do |field|
field = field.to_s
# Convert emtpy strings to nil, whether the value is a scalar or an array
new_admin_data_value = if change_set.fields[field].respond_to?(:select)

# Conditionally set new value for admin data field
new_admin_data_value = if AdminData::SERIALIZED_FIELDS.include?(field.to_sym)
# Filter out blanks if the field is a serialized field, e.g. sonyci_id.
change_set.fields[field].reject {|v| v.blank? }
elsif change_set.fields[field].blank?
# If not serialized and blank, convert to nil
nil
else # non-multiple with value present
else
# Otherwise keep value as is.
change_set.fields[field]
end

# If the AdminData field can be emptied OR if we have a non-blank value, then update the AdminData field.
if can_empty_field?(field) || new_admin_data_value.present?
admin_data.write_attribute(field, new_admin_data_value)
else
Expand Down

0 comments on commit 0eb35a6

Please sign in to comment.