<commit_before>require 'active_support/concern'
require 'active_support/core_ext/class/attribute'

require_relative 'report/queries_builder'
require_relative 'report/attach_proxy'

module Mongoid
  module Report
    extend ActiveSupport::Concern

    included do
      extend ClassMethods

      class_attribute :settings

      self.settings = {}

      def initialize
        self.class.settings.each do |klass, configuration|
          builder = QueriesBuilder.new(configuration)

          # Prepare group queries depends on the configuration in the included
          # class.
          @queries = builder.do

          # Now we have access to compiled queries to run it in aggregation
          # framework.
          configuration[:queries] = @queries
        end
      end

      def queries(klass)
        self.class.settings[klass][:queries]
      end

      # We should pass here mongoid document
      def aggregate_for(klass)
        queries = queries(Model)

        yield queries if block_given?

        klass.collection.aggregate(queries)
      end
    end

    module ClassMethods
      def attach_to(collection, &block)
        proxy = AttachProxy.new(self, collection)
        proxy.instance_eval(&block)<commit_msg>Make initialize as alias for initialize_report_module<commit_after>require 'active_support/concern'
require 'active_support/core_ext/class/attribute'

require_relative 'report/queries_builder'
require_relative 'report/attach_proxy'

module Mongoid
  module Report
    extend ActiveSupport::Concern

    included do
      extend ClassMethods

      class_attribute :settings

      self.settings = {}

      def initialize_report_module
        self.class.settings.each do |klass, configuration|
          builder = QueriesBuilder.new(configuration)

          # Prepare group queries depends on the configuration in the included
          # class.
          @queries = builder.do

          # Now we have access to compiled queries to run it in aggregation
          # framework.
          configuration[:queries] = @queries
        end
      end
      alias :initialize :initialize_report_module

      def queries(klass)
        self.class.settings[klass][:queries]
      end

      # We should pass here mongoid document
      def aggregate_for(klass)
        queries = queries(Model)

        yield queries if block_given?

        klass.collection.aggregate(queries)
      end
    end

    module ClassMethods
      def attach_to(collection, &block)
        proxy = AttachProxy.new(self, collection)
        proxy.instance_eval(&block)
{'fraction_non_alphanumeric': 0.06366459627329192, 'fraction_numerical': 0.0, 'mean_word_length': 2.594142259414226, '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': '5409600', 'n_tokens_mistral': 677, 'n_tokens_neox': 657, 'n_words': 185}