lib/publish_job.rb
#
# Copy the attributes from the source that have an equivalent in the destination
#
Copy the attributes from the source that have an equivalent in the destination
Copy the attributes from the source that have an equivalent in the destination
def copy(src, dest)
    excluded_attrs = %w[
      lock_version created_at updated_at id pub_reference_number conference_id
      linkedto_type linkedto_id parent_id title description short_title
      precis short_precis
    ].freeze
    src.attributes.each do |attr, val|
      next if !dest.attributes.key?(attr) ||
              excluded_attrs.include?(attr) ||
              dest.attributes[attr] == val ||
              val.nil?
      dest.send("#{attr}=", val)
    end
    if dest.is_a?(PublishedProgrammeItem)
      dest.parent_id = nil if dest.parent_id.present? && src.parent_id.nil?
      set_translated_attrs(%w[title short_title description], src, dest)
    end
    dest
  end
def copy ( src , dest ) excluded_attrs = %w[ lock_version created_at updated_at id pub_reference_number conference_id linkedto_type linkedto_id parent_id title description short_title precis short_precis ] . freeze src . attributes . each do | attr , val | next if ! dest . attributes . key? ( attr ) || excluded_attrs . include? ( attr ) || dest . attributes [ attr ] == val || val . nil? dest . send ( "#{attr}=" , val ) end if dest . is_a? ( PublishedProgrammeItem ) dest . parent_id = nil if dest . parent_id . present? && src . parent_id . nil? set_translated_attrs ( %w[ title short_title description ] , src , dest ) end dest end
Copy the attributes from the source that have an equivalent in the destination
Copy the attributes from the source that have an equivalent in the destination
# Define list of attributes excluded from the copy # Iterate through the source model's attributes to copy them # Skip the attribute if it meets any of the below conditions: # Not an attribute of the destination model; # Present in the list of excluded attributes; # The destination attribute value is the same as the source value; # The source attribute value is nil; # If none of the above conditions are met, copy the attribute
src
<not_specific>
dest
<not_specific>