<commit_before>module DidYouMean
  class SimilarClassFinder
    attr_reader :name, :original_message

    def self.build(exception)
      new(exception.name, exception.original_message)
    end

    def initialize(name, original_message)
      @name, @original_message = name, original_message
    end

    def did_you_mean?
      return if empty?

      output = "\n\n"
      output << "   Did you mean? #{similar_classes.first}\n"
      output << similar_classes[1..-1].map{|word| "#{' ' * 17}#{word}\n" }.join
      output
    end

    def empty?
      name.nil? || name.empty? || similar_classes.empty?
    end

    def similar_classes
      @similar_classes ||= scopes.map do |scope|
        DidYouMean::MethodMatcher.new(scope.constants, name).similar_methods.map do |constant_name|
          if scope === Object
            constant_name.to_s
          else
            "#{scope}::#{constant_name}"
          end
        end
      end.flatten
    end

    private

    def scope_base
      @scope_base ||= (/(([A-Z]\w*::)*)([A-Z]\w*)$/ =~ original_message ? $1 : "").split("::")
    end

    def scopes
      @scopes ||= scope_base.size.times.map do |count|
        eval(scope_base[0..(- count)].join("::"))
      end.reverse << Object
    end
  end
end<commit_msg>Temporary fix for a rails bug<commit_after>module DidYouMean
  class SimilarClassFinder
    attr_reader :name, :original_message

    def self.build(exception)
      new(exception.name, exception.original_message)
    end

    def initialize(name, original_message)
      @name, @original_message = name, original_message

      # temp fix for a rails bug: https://github.com/rails/rails/pull/15162
      @similar_classes = [] if @name.nil? || @name.empty?
    end

    def did_you_mean?
      return if empty?

      output = "\n\n"
      output << "   Did you mean? #{similar_classes.first}\n"
      output << similar_classes[1..-1].map{|word| "#{' ' * 17}#{word}\n" }.join
      output
    end

    def empty?
      similar_classes.empty?
    end

    def similar_classes
      @similar_classes ||= scopes.map do |scope|
        DidYouMean::MethodMatcher.new(scope.constants, name).similar_methods.map do |constant_name|
          if scope === Object
            constant_name.to_s
          else
            "#{scope}::#{constant_name}"
          end
        end
      end.flatten
    end

    private

    def scope_base
      @scope_base ||= (/(([A-Z]\w*::)*)([A-Z]\w*)$/ =~ original_message ? $1 : "").split("::")
    end

    def scopes
      @scopes ||= scope_base.size.times.map do |count|
        eval(scope_base[0..(- count)].join("::"))
      end.reverse << Object
    end
  end
end
{'fraction_non_alphanumeric': 0.13873265841769777, 'fraction_numerical': 0.006374203224596925, 'mean_word_length': 2.38149556400507, 'pattern_counts': {'":': 4, '<': 15, '<?xml version=': 0, '>': 3, 'https://': 1, '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': '6722372', 'n_tokens_mistral': 886, 'n_tokens_neox': 850, 'n_words': 185}