<commit_before>require 'sequencer/unit/import/common/model/mixin/handle_failure'

class Sequencer
  class Unit
    module Import
      module Common
        module Model
          module Associations
            class Assign < Sequencer::Unit::Base
              include ::Sequencer::Unit::Import::Common::Model::Mixin::HandleFailure

              uses :instance, :associations, :instance_action, :dry_run
              provides :instance_action

              def process
                return if dry_run
                return if instance.blank?

                instance.assign_attributes(associations)

                # execute associations check only if needed for performance reasons
                return if instance_action != :unchanged
                return if !changed?
                state.provide(:instance_action, :changed)
              rescue => e
                handle_failure(e)
              end

              private

              def changed?
                logger.debug("Changed instance associations: #{changes.inspect}")
                changes.present?
              end

              def changes
                @changes ||= begin
                  return {} if associations.blank?
                  associations.collect do |association, value|
                    before = compareable(instance.send(association))
                    after  = compareable(value)
                    next if before == after
                    [association, [before, after]]
                  end.compact.to_h.with_indifferent_access
                end
              end

              def compareable(value)
                return nil if value.blank?
                return value.sort if value.respond_to(:sort)
                value
              end
            end
          end
        end
      end
    end
  end
end<commit_msg>Fixed bug: Wrong method name.<commit_after>require 'sequencer/unit/import/common/model/mixin/handle_failure'

class Sequencer
  class Unit
    module Import
      module Common
        module Model
          module Associations
            class Assign < Sequencer::Unit::Base
              include ::Sequencer::Unit::Import::Common::Model::Mixin::HandleFailure

              uses :instance, :associations, :instance_action, :dry_run
              provides :instance_action

              def process
                return if dry_run
                return if instance.blank?

                instance.assign_attributes(associations)

                # execute associations check only if needed for performance reasons
                return if instance_action != :unchanged
                return if !changed?
                state.provide(:instance_action, :changed)
              rescue => e
                handle_failure(e)
              end

              private

              def changed?
                logger.debug("Changed instance associations: #{changes.inspect}")
                changes.present?
              end

              def changes
                @changes ||= begin
                  return {} if associations.blank?
                  associations.collect do |association, value|
                    before = compareable(instance.send(association))
                    after  = compareable(value)
                    next if before == after
                    [association, [before, after]]
                  end.compact.to_h.with_indifferent_access
                end
              end

              def compareable(value)
                return nil if value.blank?
                return value.sort if value.respond_to?(:sort)
                value
              end
            end
          end
        end
      end
    end
  end
end
{'fraction_non_alphanumeric': 0.06150953532097771, 'fraction_numerical': 0.0, 'mean_word_length': 1.351010101010101, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 5, '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': '6742244', 'n_tokens_mistral': 850, 'n_tokens_neox': 790, 'n_words': 223}