<commit_before>module Bullet
  module ActiveRecord
    def self.enable
      ::ActiveRecord::Base.class_eval do
        class << self
          alias_method :bullet_find_every, :find_every
          # if select a collection of objects, then these objects have possible to cause N+1 query
          # if select only one object, then the only one object has impossible to cause N+1 query
          def find_every(options)
            records = bullet_find_every(options)

            if records 
              if records.size > 1
                Bullet::Association.add_possible_objects(records)
              elsif records.size == 1
                Bullet::Association.add_impossible_object(records.first)
              end
            end

            records
          end

          alias_method :bullet_preload_associations, :preload_associations
          # add include for one to many associations query
          def preload_associations(records, associations, preload_options={})
            records = [records].flatten.compact.uniq
            return if records.empty?
            records.each do |record|
              Bullet::Association.add_association(record, associations)
            end
            bullet_preload_associations(records, associations, preload_options={})
          end

          # define one to many associations
          alias_method :bullet_collection_reader_method, :collection_reader_method
          def collection_reader_method(reflection, association_proxy_class)
            Bullet::Association.define_association(self, reflection.name)
            bullet_collection_reader_method(reflection, association_proxy_class)
          end
        end
      end

      ::ActiveRecord::Associations::AssociationCollection.class_eval do
        # call one to many associations
        alias_method :bullet_load_target, :load_target
        def load_target
          Bullet::Association.call_association(@owner, @reflection.name)
          bullet_load_target
        end  
      end
      
      ::ActiveRecord::Associations::AssociationProxy.class_eval do<commit_msg>add namespace and reset to origin_xxx method, like this name style<commit_after>module Bullet
  module ActiveRecord
    def self.enable
      ::ActiveRecord::Base.class_eval do
        class << self
          alias_method :bullet_find_every, :find_every
          # if select a collection of objects, then these objects have possible to cause N+1 query
          # if select only one object, then the only one object has impossible to cause N+1 query
          def find_every(options)
            records = bullet_find_every(options)

            if records 
              if records.size > 1
                Bullet::Association.add_possible_objects(records)
              elsif records.size == 1
                Bullet::Association.add_impossible_object(records.first)
              end
            end

            records
          end
        end
      end

      ::ActiveRecord::AssociationPreload::ClassMethods.class_eval do
        alias_method :bullet_preload_associations, :preload_associations
        # add include for one to many associations query
        def preload_associations(records, associations, preload_options={})
          records = [records].flatten.compact.uniq
          return if records.empty?
          records.each do |record|
            Bullet::Association.add_association(record, associations)
          end
          bullet_preload_associations(records, associations, preload_options={})
        end
      end

      ::ActiveRecord::Associations::ClassMethods.class_eval do
        # define one to many associations
        alias_method :bullet_collection_reader_method, :collection_reader_method
        def collection_reader_method(reflection, association_proxy_class)
          Bullet::Association.define_association(self, reflection.name)
          bullet_collection_reader_method(reflection, association_proxy_class)
        end
      end

      ::ActiveRecord::Associations::AssociationCollection.class_eval do
        # call one to many associations
        alias_method :bullet_load_target, :load_target
        def load_target
          Bullet::Association.call_association(@owner, @reflection.name)
          bullet_load_target
        end  
      end
      
      ::ActiveRecord::Associations::AssociationProxy.class_eval do
{'fraction_non_alphanumeric': 0.05839248912296771, 'fraction_numerical': 0.0018319212273872224, 'mean_word_length': 2.4584323040380047, 'pattern_counts': {'":': 0, '<': 7, '<?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': '2822504', 'n_tokens_mistral': 1086, 'n_tokens_neox': 1046, 'n_words': 273}