<commit_before>class RemoteTranslations::Caller
  attr_reader :remote_translation

  def initialize(remote_translation)
    @remote_translation = remote_translation
  end

  def call
    update_resource
    destroy_remote_translation
  end

  private

    def update_resource
      Globalize.with_locale(locale) do
        resource.translated_attribute_names.each_with_index do |field, index|
          resource.send(:"#{field}=", translations[index])
        end
      end
      resource.save
    end

    def destroy_remote_translation
      if resource.valid?
        remote_translation.destroy
      else
        remote_translation.update(error_message: resource.errors.messages)
      end
      resource.save<commit_msg>Don't try to save invalid resources<commit_after>class RemoteTranslations::Caller
  attr_reader :remote_translation

  def initialize(remote_translation)
    @remote_translation = remote_translation
  end

  def call
    update_resource
    destroy_remote_translation
  end

  private

    def update_resource
      Globalize.with_locale(locale) do
        resource.translated_attribute_names.each_with_index do |field, index|
          resource.send(:"#{field}=", translations[index])
        end
      end
      resource.save
    end

    def destroy_remote_translation
      if resource.valid?
        remote_translation.destroy
        resource.save!
      else
        remote_translation.update(error_message: resource.errors.messages)
      end
{'fraction_non_alphanumeric': 0.05830508474576271, 'fraction_numerical': 0.0, 'mean_word_length': 3.122905027932961, 'pattern_counts': {'":': 0, '<': 3, '<?xml version=': 0, '>': 3, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 0, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '2994141', 'n_tokens_mistral': 399, 'n_tokens_neox': 387, 'n_words': 82}