<commit_before>require "active_support/callbacks"
require "rails_callback_log/version"
require 'benchmark'

module RailsCallbackLog
  class << self
    def matches_filter?(str)
      source_location_filters.any? { |f| str.start_with?(f) }
    end

    private

    def source_location_filters
      @@filters ||= %w(app lib).map { |dir| (::Rails.root + dir).to_s }
    end
  end
end

if ::Gem::Requirement.new("~> 4.2.0").satisfied_by?(::Rails.gem_version)
  module ActiveSupport
    module Callbacks
      class Callback
        def make_lambda_with_log(filter)
          original_lambda = make_lambda_without_log(filter)
          lambda { |*args|
            if caller.any? { |line| ::RailsCallbackLog.matches_filter?(line) }
              ::Rails.logger.debug(format("Callback: %s", filter))
            end
            original_lambda.call(*args)
          }
        end
        alias_method_chain :make_lambda, :log
      end
    end
  end
else
  warn "RailsCallbackLog does not support rails version: #{::Rails.gem_version}"
end<commit_msg>Pass block to original lambda<commit_after>require "active_support/callbacks"
require "rails_callback_log/version"
require 'benchmark'

module RailsCallbackLog
  class << self
    def matches_filter?(str)
      source_location_filters.any? { |f| str.start_with?(f) }
    end

    private

    def source_location_filters
      @@filters ||= %w(app lib).map { |dir| (::Rails.root + dir).to_s }
    end
  end
end

if ::Gem::Requirement.new("~> 4.2.0").satisfied_by?(::Rails.gem_version)
  module ActiveSupport
    module Callbacks
      class Callback
        def make_lambda_with_log(filter)
          original_lambda = make_lambda_without_log(filter)
          lambda { |*args, &block|
            if caller.any? { |line| ::RailsCallbackLog.matches_filter?(line) }
              ::Rails.logger.debug(format("Callback: %s", filter))
            end
            original_lambda.call(*args, &block)
          }
        end
        alias_method_chain :make_lambda, :log
      end
    end
  end
else
  warn "RailsCallbackLog does not support rails version: #{::Rails.gem_version}"
end
{'fraction_non_alphanumeric': 0.11194731890874883, 'fraction_numerical': 0.0028222013170272815, 'mean_word_length': 2.9171270718232045, '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': '1971913', 'n_tokens_mistral': 679, 'n_tokens_neox': 670, 'n_words': 143}