class AssetManager::AttachmentUpdater::ReplacementIdUpdates
  def self.call(attachment_data)
    return [] unless attachment_data.replaced?

    replacement = attachment_data.replaced_by

    Enumerator.new do |enum|
      enum.yield AssetManager::AttachmentUpdater::Update.new(
        attachment_data, attachment_data.file, replacement_legacy_url_path: replacement.file.asset_manager_path
      )

      if attachment_data.pdf?
        if replacement.pdf?
          enum.yield AssetManager::AttachmentUpdater::Update.new(
            attachment_data, attachment_data.file.thumbnail, replacement_legacy_url_path: replacement.file.thumbnail.asset_manager_path
          )
        else
          enum.yield AssetManager::AttachmentUpdater::Update.new(
            attachment_data, attachment_data.file.thumbnail, replacement_legacy_url_path: replacement.file.asset_manager_path
          )
        end
      end
    end
  end
end

class AssetManager::AttachmentUpdater::ReplacementIdUpdates
  def self.call(attachment_data)
    return [] unless attachment_data.replaced?

    replacement = attachment_data.replaced_by

    Enumerator.new do |enum|
      enum.yield(
        AssetManager::AttachmentUpdater::Update.new(
          attachment_data,
          attachment_data.file,
          replacement_legacy_url_path: replacement.file.asset_manager_path,
        ),
      )

      if attachment_data.pdf?
        replacement_legacy_url_path = if replacement.pdf?
                                        replacement.file.thumbnail.asset_manager_path
                                      else
                                        replacement.file.asset_manager_path
                                      end
        enum.yield(
          AssetManager::AttachmentUpdater::Update.new(
            attachment_data,
            attachment_data.file.thumbnail,
            replacement_legacy_url_path: replacement_legacy_url_path,
          ),
        )
      end
    end
  end
end

Refactor the ReplacementIdUpdates class for readability
Refactor the ReplacementIdUpdates class for readability

Format to avoid the lines which were too long. Also reduce the code
duplication by using a variable.
