<commit_before>require 'active_support/core_ext/array/wrap'

module ActsAsParanoid
  module Validations
    def self.included(base)
      base.extend ClassMethods
    end

    class UniquenessWithoutDeletedValidator < ActiveRecord::Validations::UniquenessValidator
      def validate_each(record, attribute, value)
        finder_class = find_finder_class_for(record)
        table = finder_class.arel_table

        # TODO: Use record.class.column_types[attribute.to_s].coder ?
        coder = record.class.column_types[attribute.to_s]

        if value && coder
          value = coder.type_cast_for_write value
        end

        relation = build_relation(finder_class, table, attribute, value)
        [Array(finder_class.primary_key), Array(record.send(:id))].transpose.each do |pk_key, pk_value|
          relation = relation.and(table[pk_key.to_sym].not_eq(pk_value))
        end if record.persisted?

        Array.wrap(options[:scope]).each do |scope_item|
          scope_value = record.send(scope_item)
          relation = relation.and(table[scope_item].eq(scope_value))
        end

        # Re-add ActsAsParanoid default scope conditions manually.
        if finder_class.unscoped.where(finder_class.paranoid_default_scope_sql).where(relation).exists?
          record.errors.add(attribute, :taken, options.except(:case_sensitive, :scope).merge(:value => value))
        end
      end
    end

    module ClassMethods<commit_msg>Make #validate_each work with AR 4.2<commit_after>require 'active_support/core_ext/array/wrap'

module ActsAsParanoid
  module Validations
    def self.included(base)
      base.extend ClassMethods
    end

    class UniquenessWithoutDeletedValidator < ActiveRecord::Validations::UniquenessValidator
      def validate_each(record, attribute, value)
        finder_class = find_finder_class_for(record)
        table = finder_class.arel_table

        # TODO: Use record.class.column_types[attribute.to_s].coder ?
        coder = record.class.column_types[attribute.to_s]

        if value && coder
          value = if coder.respond_to? :type_cast_for_database
                    coder.type_cast_for_database value
                  else
                    coder.type_cast_for_write value
                  end
        end

        relation = build_relation(finder_class, table, attribute, value)
        [Array(finder_class.primary_key), Array(record.send(:id))].transpose.each do |pk_key, pk_value|
          relation = relation.and(table[pk_key.to_sym].not_eq(pk_value))
        end if record.persisted?

        Array.wrap(options[:scope]).each do |scope_item|
          scope_value = record.send(scope_item)
          relation = relation.and(table[scope_item].eq(scope_value))
        end

        # Re-add ActsAsParanoid default scope conditions manually.
        if finder_class.unscoped.where(finder_class.paranoid_default_scope_sql).where(relation).exists?
          record.errors.add(attribute, :taken, options.except(:case_sensitive, :scope).merge(:value => value))
        end
      end
    end

    module ClassMethods
{'fraction_non_alphanumeric': 0.08896103896103896, 'fraction_numerical': 0.0006493506493506494, 'mean_word_length': 3.032722513089005, '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': '3850308', 'n_tokens_mistral': 919, 'n_tokens_neox': 885, 'n_words': 161}