<commit_before>module RailsDevelopmentBoost
  module DependenciesPatch
    module InstrumentationPatch
      module Instrumenter
        delegate :boost_log, :to => 'ActiveSupport::Dependencies'
        
        def self.included(mod)
          mod.extend(ClassMethods)
        end
        
        module ClassMethods
          def included(klass)
            (public_instance_methods(false) + private_instance_methods(false) + protected_instance_methods(false)).each do |method|
              if m = method.to_s.match(/(.+)_with_(.+)/)
                klass.alias_method_chain m[1], m[2]
              end
            end

            super
          end
        end
      end
      
      module LoadedFile
        include Instrumenter
        
        def boost_inspect
          "\#<LoadedFile #{relative_path} #{inspect_constants(@constants)}>"
        end
        
        def add_constants_with_instrumentation(new_constants)
          boost_log('ADD_CONSTANTS', "#{boost_inspect} <- #{inspect_constants(new_constants)}")
          add_constants_without_instrumentation(new_constants)
        end

      private
        RAILS_ROOT = /\A#{Rails.root.to_s}/
        
        def inspect_constants(constants_arr)
          "[#{constants_arr.join(', ')}]"
        end

        def relative_path
          @path.sub(RAILS_ROOT, '')
        end
        
        def self.included(klass)
          klass.singleton_class.send :include, ClassMethods
          super
        end
        
        module ClassMethods
          include Instrumenter
          
          def unload_containing_file_with_instrumentation(const_name, file)
            boost_log('UNLOAD_CONTAINING_FILE', "#{const_name} -> #{file.boost_inspect}")
            unload_containing_file_without_instrumentation(const_name, file)
          end
        end
      end
      
      module Files
        include Instrumenter
        
        def unload_modified_file_with_instrumentation(file)
          boost_log('CHANGED', "#{file.boost_inspect}")
          unload_modified_file_without_instrumentation(file)
        end
      end
      
      def self.apply!
        ActiveSupport::Dependencies.extend self
        RailsDevelopmentBoost::LoadedFile.send :include, LoadedFile
        RailsDevelopmentBoost::LoadedFile::Files.send :include, Files
      end
      
      def unload_modified_files!
        boost_log('--- START ---')
        super
        boost_log('--- END ---')
      end<commit_msg>Make sure not to double apply!<commit_after>module RailsDevelopmentBoost
  module DependenciesPatch
    module InstrumentationPatch
      module Instrumenter
        delegate :boost_log, :to => 'ActiveSupport::Dependencies'
        
        def self.included(mod)
          mod.extend(ClassMethods)
        end
        
        module ClassMethods
          def included(klass)
            (public_instance_methods(false) + private_instance_methods(false) + protected_instance_methods(false)).each do |method|
              if m = method.to_s.match(/(.+)_with_(.+)/)
                klass.alias_method_chain m[1], m[2]
              end
            end

            super
          end
        end
      end
      
      module LoadedFile
        include Instrumenter
        
        def boost_inspect
          "\#<LoadedFile #{relative_path} #{inspect_constants(@constants)}>"
        end
        
        def add_constants_with_instrumentation(new_constants)
          boost_log('ADD_CONSTANTS', "#{boost_inspect} <- #{inspect_constants(new_constants)}")
          add_constants_without_instrumentation(new_constants)
        end

      private
        RAILS_ROOT = /\A#{Rails.root.to_s}/
        
        def inspect_constants(constants_arr)
          "[#{constants_arr.join(', ')}]"
        end

        def relative_path
          @path.sub(RAILS_ROOT, '')
        end
        
        def self.included(klass)
          klass.singleton_class.send :include, ClassMethods
          super
        end
        
        module ClassMethods
          include Instrumenter
          
          def unload_containing_file_with_instrumentation(const_name, file)
            boost_log('UNLOAD_CONTAINING_FILE', "#{const_name} -> #{file.boost_inspect}")
            unload_containing_file_without_instrumentation(const_name, file)
          end
        end
      end
      
      module Files
        include Instrumenter
        
        def unload_modified_file_with_instrumentation(file)
          boost_log('CHANGED', "#{file.boost_inspect}")
          unload_modified_file_without_instrumentation(file)
        end
      end
      
      def self.apply!
        unless applied?
          ActiveSupport::Dependencies.extend self
          RailsDevelopmentBoost::LoadedFile.send :include, LoadedFile
          RailsDevelopmentBoost::LoadedFile::Files.send :include, Files
        end
      end
      
      def self.applied?
        ActiveSupport::Dependencies.include?(self)
      end
      
      def unload_modified_files!
        boost_log('--- START ---')
        super
        boost_log('--- END ---')
      end
{'fraction_non_alphanumeric': 0.08184143222506395, 'fraction_numerical': 0.0007869368483179224, 'mean_word_length': 1.9421296296296295, 'pattern_counts': {'":': 0, '<': 7, '<?xml version=': 0, '>': 9, 'https://': 0, 'lorem ipsum': 0, 'www.': 0, 'xml': 0}, 'pii_count': 0, 'substrings_counts': 0, 'word_list_counts': {'cursed_substrings.json': 6, 'profanity_word_list.json': 0, 'sexual_word_list.json': 0, 'zh_pornsignals.json': 0}}
{'dir': 'git-commits-cleaned', 'id': '6441466', 'n_tokens_mistral': 1428, 'n_tokens_neox': 1398, 'n_words': 245}