<commit_before>require "simple_taggable/version"

require "active_record"

require "generators/simple_taggable/install"
require "simple_taggable/tag_list"
require "simple_taggable/models/tag"
require "simple_taggable/models/tagging"

require "active_support/concern"

module SimpleTaggable
  extend ActiveSupport::Concern

  included do
    has_many :taggings, as: :taggable, class_name: "SimpleTaggable::Models::Tagging", dependent: :destroy
    has_many :tags, through: :taggings, class_name: "SimpleTaggable::Models::Tag"

    scope :tagged_with, ->(*tag_name, match_all: false, exclude: false) {
      raise "`tagged_with` cannot use :match_all and :exclude at the same time" if match_all && exclude
      tag_scope = SimpleTaggable::Models::Tag.where(name: tag_name)

      if exclude
        users = User.joins(:tags).merge(tag_scope).group(%W("#{table_name}"."id"))
        where.not(id: users.pluck(:id))
      else
        User.joins(:tags).merge(tag_scope).group(%W("#{table_name}"."id")).tap do |scope|
          break scope.having("count(*) == ?", tag_name.length) if match_all
        end
      end
    }

    after_save :__sync_tags__
  end

  module ClassMethods
    def inherited(child)
      super
      child.instance_variable_set("@__tag_filters__", __tag_filters__.dup)
      child.instance_variable_set("@__tag_converters__", __tag_converters__.dup)
    end

    def add_tag_filter(filter_proc, &block)
      pr = filter_proc || block
      self.__tag_filters__ << pr
    end

    def reset_tag_filters
      __tag_filters__.clear
    end

    def add_tag_converter(converter_proc, &block)
      pr = converter_proc || block
      self.__tag_converters__ << pr
    end<commit_msg>Fix typo<commit_after>require "simple_taggable/version"

require "active_record"

require "generators/simple_taggable/install"
require "simple_taggable/tag_list"
require "simple_taggable/models/tag"
require "simple_taggable/models/tagging"

require "active_support/concern"

module SimpleTaggable
  extend ActiveSupport::Concern

  included do
    has_many :taggings, as: :taggable, class_name: "SimpleTaggable::Models::Tagging", dependent: :destroy
    has_many :tags, through: :taggings, class_name: "SimpleTaggable::Models::Tag"

    scope :tagged_with, ->(*tag_name, match_all: false, exclude: false) {
      raise "`tagged_with` cannot use :match_all and :exclude at the same time" if match_all && exclude
      tag_scope = SimpleTaggable::Models::Tag.where(name: tag_name)

      if exclude
        users = User.joins(:tags).merge(tag_scope).group(%W("#{table_name}"."id"))
        where.not(id: users.pluck(:id))
      else
        User.joins(:tags).merge(tag_scope).group(%W("#{table_name}"."id")).tap do |scope|
          break scope.having("count(*) = ?", tag_name.length) if match_all
        end
      end
    }

    after_save :__sync_tags__
  end

  module ClassMethods
    def inherited(child)
      super
      child.instance_variable_set("@__tag_filters__", __tag_filters__.dup)
      child.instance_variable_set("@__tag_converters__", __tag_converters__.dup)
    end

    def add_tag_filter(filter_proc, &block)
      pr = filter_proc || block
      self.__tag_filters__ << pr
    end

    def reset_tag_filters
      __tag_filters__.clear
    end

    def add_tag_converter(converter_proc, &block)
      pr = converter_proc || block
      self.__tag_converters__ << pr
    end
{'fraction_non_alphanumeric': 0.11277974087161366, 'fraction_numerical': 0.0, 'mean_word_length': 3.908959537572254, 'pattern_counts': {'":': 0, '<': 11, '<?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': '2721572', 'n_tokens_mistral': 1137, 'n_tokens_neox': 1104, 'n_words': 222}