<commit_before># frozen_string_literal: true

require 'active_support/core_ext/module/delegation'
require 'set'
require 'uniform_notifier'
require 'bullet/ext/object'
require 'bullet/ext/string'
require 'bullet/dependency'
require 'bullet/stack_trace_filter'

module Bullet
  extend Dependency

  autoload :ActiveRecord, "bullet/#{active_record_version}" if active_record?
  autoload :Mongoid, "bullet/#{mongoid_version}" if mongoid?
  autoload :Rack, 'bullet/rack'
  autoload :ActiveJob, 'bullet/active_job'
  autoload :Notification, 'bullet/notification'
  autoload :Detector, 'bullet/detector'
  autoload :Registry, 'bullet/registry'
  autoload :NotificationCollector, 'bullet/notification_collector'

  if defined?(Rails::Railtie)
    class BulletRailtie < Rails::Railtie
      initializer 'bullet.configure_rails_initialization' do |app|
        app.middleware.use Bullet::Rack
      end
    end
  end

  class << self
    attr_writer :n_plus_one_query_enable,
                :unused_eager_loading_enable,
                :counter_cache_enable,
                :stacktrace_includes,
                :stacktrace_excludes,
                :skip_html_injection
    attr_reader :whitelist
    attr_accessor :add_footer, :orm_patches_applied, :skip_http_headers

    available_notifiers =
      UniformNotifier::AVAILABLE_NOTIFIERS.select { |notifier| notifier != :raise }.map { |notifier| "#{notifier}=" }
    available_notifiers_options = { to: UniformNotifier }
    delegate(*available_notifiers, **available_notifiers_options)

    def raise=(should_raise)
      UniformNotifier.raise = (should_raise ? Notification::UnoptimizedQueryError : false)
    end

    DETECTORS = [
      Bullet::Detector::NPlusOneQuery,
      Bullet::Detector::UnusedEagerLoading,
      Bullet::Detector::CounterCache
    ].freeze

    def enable=(enable)
      @enable = @n_plus_one_query_enable = @unused_eager_loading_enable = @counter_cache_enable = enable

      if enable?
        reset_whitelist
        unless orm_patches_applied
          self.orm_patches_applied = true
          Bullet::Mongoid.enable if mongoid?
          Bullet::ActiveRecord.enable if active_record?
        end
      end
    end

    def enable?
      !!@enable
    end

    def app_root
      @app_root ||= (defined?(::Rails.root) ? Rails.root.to_s : Dir.pwd).to_s
    end

    def n_plus_one_query_enable?
      enable? && !!@n_plus_one_query_enable
    end

    def unused_eager_loading_enable?
      enable? && !!@unused_eager_loading_enable
    end

    def counter_cache_enable?
      enable? && !!@counter_cache_enable
    end

    def stacktrace_includes
      @stacktrace_includes ||= []
    end

    def stacktrace_excludes
      @stacktrace_excludes ||= []
    end

    def add_whitelist(options)
      reset_whitelist
      @whitelist[options[:type]][options[:class_name]] ||= []
      @whitelist[options[:type]][options[:class_name]] << options[:association].to_sym
    end
<commit_msg>Do not use `Rails.root` if it's nil<commit_after># frozen_string_literal: true

require 'active_support/core_ext/module/delegation'
require 'set'
require 'uniform_notifier'
require 'bullet/ext/object'
require 'bullet/ext/string'
require 'bullet/dependency'
require 'bullet/stack_trace_filter'

module Bullet
  extend Dependency

  autoload :ActiveRecord, "bullet/#{active_record_version}" if active_record?
  autoload :Mongoid, "bullet/#{mongoid_version}" if mongoid?
  autoload :Rack, 'bullet/rack'
  autoload :ActiveJob, 'bullet/active_job'
  autoload :Notification, 'bullet/notification'
  autoload :Detector, 'bullet/detector'
  autoload :Registry, 'bullet/registry'
  autoload :NotificationCollector, 'bullet/notification_collector'

  if defined?(Rails::Railtie)
    class BulletRailtie < Rails::Railtie
      initializer 'bullet.configure_rails_initialization' do |app|
        app.middleware.use Bullet::Rack
      end
    end
  end

  class << self
    attr_writer :n_plus_one_query_enable,
                :unused_eager_loading_enable,
                :counter_cache_enable,
                :stacktrace_includes,
                :stacktrace_excludes,
                :skip_html_injection
    attr_reader :whitelist
    attr_accessor :add_footer, :orm_patches_applied, :skip_http_headers

    available_notifiers =
      UniformNotifier::AVAILABLE_NOTIFIERS.select { |notifier| notifier != :raise }.map { |notifier| "#{notifier}=" }
    available_notifiers_options = { to: UniformNotifier }
    delegate(*available_notifiers, **available_notifiers_options)

    def raise=(should_raise)
      UniformNotifier.raise = (should_raise ? Notification::UnoptimizedQueryError : false)
    end

    DETECTORS = [
      Bullet::Detector::NPlusOneQuery,
      Bullet::Detector::UnusedEagerLoading,
      Bullet::Detector::CounterCache
    ].freeze

    def enable=(enable)
      @enable = @n_plus_one_query_enable = @unused_eager_loading_enable = @counter_cache_enable = enable

      if enable?
        reset_whitelist
        unless orm_patches_applied
          self.orm_patches_applied = true
          Bullet::Mongoid.enable if mongoid?
          Bullet::ActiveRecord.enable if active_record?
        end
      end
    end

    def enable?
      !!@enable
    end

    # Rails.root might be nil if `railties` is a dependency on a project that does not use Rails
    def app_root
      @app_root ||= (defined?(::Rails.root) && !::Rails.root.nil? ? Rails.root.to_s : Dir.pwd).to_s
    end

    def n_plus_one_query_enable?
      enable? && !!@n_plus_one_query_enable
    end

    def unused_eager_loading_enable?
      enable? && !!@unused_eager_loading_enable
    end

    def counter_cache_enable?
      enable? && !!@counter_cache_enable
    end

    def stacktrace_includes
      @stacktrace_includes ||= []
    end

    def stacktrace_excludes
      @stacktrace_excludes ||= []
    end

    def add_whitelist(options)
      reset_whitelist
      @whitelist[options[:type]][options[:class_name]] ||= []
      @whitelist[options[:type]][options[:class_name]] << options[:association].to_sym
    end

{'fraction_non_alphanumeric': 0.09658809955496951, 'fraction_numerical': 0.0, 'mean_word_length': 3.498146775389177, 'pattern_counts': {'":': 0, '<': 13, '<?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': '3545405', 'n_tokens_mistral': 1986, 'n_tokens_neox': 1900, 'n_words': 358}