<commit_before>module UsefullScopes
  autoload :Version, 'usefull_scopes/version'
  extend ActiveSupport::Concern

  included do
    scope :random, order("RANDOM()")
    scope :exclude, lambda {|collection_or_object|
      collection = Array(collection_or_object)
      values = collection.map do |id_or_object|
        id_or_object.is_a?(ActiveRecord::Base) ? id_or_object.id : id_or_object
      end
      return scoped unless value
      where("#{quoted_table_name}.id in (?)", values)
    }

    attribute_names.each do |a|
      scope "by_#{a}", order("#{quoted_table_name}.#{a} DESC")
      scope "asc_by_#{a}", order("#{quoted_table_name}.#{a} ASC")
      scope "like_by_#{a}", lambda {|term|
        quoted_term = connection.quote(term + '%')
        where("lower(#{quoted_table_name}.#{a}) like #{quoted_term}")
      }
      scope "ilike_by_#{a}", lambda {|term|
        quoted_term = connection.quote(term + '%')
        where("#{quoted_table_name}.#{a} ilike #{quoted_term}")
      }
    end
  end
end
<commit_msg>fixed exclude collection<commit_after>module UsefullScopes
  autoload :Version, 'usefull_scopes/version'
  extend ActiveSupport::Concern

  included do
    scope :random, order("RANDOM()")
    scope :exclude, lambda {|collection_or_object|
      collection = Array(collection_or_object)
      values = collection.map do |id_or_object|
        id_or_object.is_a?(ActiveRecord::Base) ? id_or_object.id : id_or_object
      end
      return scoped unless values.any?
      where("#{quoted_table_name}.id in (?)", values)
    }

    attribute_names.each do |a|
      scope "by_#{a}", order("#{quoted_table_name}.#{a} DESC")
      scope "asc_by_#{a}", order("#{quoted_table_name}.#{a} ASC")
      scope "like_by_#{a}", lambda {|term|
        quoted_term = connection.quote(term + '%')
        where("lower(#{quoted_table_name}.#{a}) like #{quoted_term}")
      }
      scope "ilike_by_#{a}", lambda {|term|
        quoted_term = connection.quote(term + '%')
        where("#{quoted_table_name}.#{a} ilike #{quoted_term}")
      }
    end
  end
end

{'fraction_non_alphanumeric': 0.15079748670855486, 'fraction_numerical': 0.0, 'mean_word_length': 3.519650655021834, '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': '2932918', 'n_tokens_mistral': 704, 'n_tokens_neox': 723, 'n_words': 132}