<commit_before># Container module for all SQL:Origin methods.

module SQLOrigin
  # Paths or path prefixes that are filtered from the backtrace.
  LIBRARY_PATHS = %w(
    vendor
  )

  # @return [Array<String>] The backtrace less library paths.

  def self.filtered_backtrace
    caller.map do |line|
      line.sub /^#{Regexp.escape Rails.root.to_s}\//, ''
    end.select do |line|
      !line.starts_with?("/") &&
          !line.starts_with?("(") &&
          LIBRARY_PATHS.none? { |path| line.starts_with?(path) }
    end
  end

  # Enables SQL:Origin backtrace logging to the Rails log.

  def self.append_to_log
    %w( PostgreSQLAdapter MysqlAdapter Mysql2Adapter OracleAdapter SQLiteAdapter ).each do |name|
      adapter = ActiveRecord::ConnectionAdapters.const_get(name.to_sym) rescue nil
      if adapter
        adapter.send :include, SQLOrigin::LogHook
      end
    end
    ActiveRecord::LogSubscriber.send :include, SQLOrigin::LogSubscriber
  end

  # Enables SQL:Origin backtrace logging to SQL query comments.

  def self.append_to_query<commit_msg>Fix for new SQLite adapter name<commit_after># Container module for all SQL:Origin methods.

module SQLOrigin
  # Paths or path prefixes that are filtered from the backtrace.
  LIBRARY_PATHS = %w(
    vendor
  )

  # @return [Array<String>] The backtrace less library paths.

  def self.filtered_backtrace
    caller.map do |line|
      line.sub /^#{Regexp.escape Rails.root.to_s}\//, ''
    end.select do |line|
      !line.starts_with?("/") &&
          !line.starts_with?("(") &&
          LIBRARY_PATHS.none? { |path| line.starts_with?(path) }
    end
  end

  # Enables SQL:Origin backtrace logging to the Rails log.

  def self.append_to_log
    %w( PostgreSQLAdapter MysqlAdapter Mysql2Adapter OracleAdapter SQLiteAdapter SQLite3Adapter ).each do |name|
      adapter = ActiveRecord::ConnectionAdapters.const_get(name.to_sym) rescue nil
      if adapter
        adapter.send :include, SQLOrigin::LogHook
      end
    end
    ActiveRecord::LogSubscriber.send :include, SQLOrigin::LogSubscriber
  end

  # Enables SQL:Origin backtrace logging to SQL query comments.

  def self.append_to_query
{'fraction_non_alphanumeric': 0.09607390300230947, 'fraction_numerical': 0.0013856812933025404, 'mean_word_length': 3.358148893360161, 'pattern_counts': {'":': 0, '<': 5, '<?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': '3901550', 'n_tokens_mistral': 719, 'n_tokens_neox': 672, 'n_words': 187}