<commit_before>require "interception"

require "did_you_mean/version"
require "did_you_mean/core_ext/name_error"
require "did_you_mean/finders"
require "did_you_mean/formatters"

module DidYouMean
  Interception.listen(->(exception, binding) {
    # On IRB/pry console, this event is called twice. In the second event,
    # we get IRB/pry binding. So it shouldn't override @frame_binding if
    # it's already defined.
    if exception.is_a?(NameError) && !exception.instance_variable_defined?(:@frame_binding)
      exception.instance_variable_set(:@frame_binding, binding)
    end
  })

  @@enabled = true

  def self.enabled?
    @@enabled
  end

  def self.disabled?
    !enabled?
  end

  def self.without_suggestions
    tmp, @@enabled = @@enabled, false
    yield
  ensure
    @@enabled = tmp
  end

  def self.formatter=(formatter)
    @@formatter = formatter
  end

  def self.formatter
    @@formatter ||= Formatters::Plain
  end

  def self.finders
    @@finders ||= Hash.new(NullFinder)
  end

  finders.merge!({
    "NameError"                           => NameErrorFinders,
    "ActiveRecord::UnknownAttributeError" => SimilarAttributeFinder,
  })

  case RUBY_ENGINE
  when 'ruby', 'jruby'
    finders["NoMethodError"] = SimilarMethodFinder
  when 'rbx'
    finders["NoMethodError"] =
      if (___ rescue $!).class.to_s == "NameError" # For rbx > 2.5.0
        SimilarMethodFinder
      else
        SimilarMethodFinder::RubiniusSupport       # For rbx < 2.5.0
      end<commit_msg>Fix the build for ActiveRecord 5.0<commit_after>require "interception"

require "did_you_mean/version"
require "did_you_mean/core_ext/name_error"
require "did_you_mean/finders"
require "did_you_mean/formatters"

module DidYouMean
  Interception.listen(->(exception, binding) {
    # On IRB/pry console, this event is called twice. In the second event,
    # we get IRB/pry binding. So it shouldn't override @frame_binding if
    # it's already defined.
    if exception.is_a?(NameError) && !exception.instance_variable_defined?(:@frame_binding)
      exception.instance_variable_set(:@frame_binding, binding)
    end
  })

  @@enabled = true

  def self.enabled?
    @@enabled
  end

  def self.disabled?
    !enabled?
  end

  def self.without_suggestions
    tmp, @@enabled = @@enabled, false
    yield
  ensure
    @@enabled = tmp
  end

  def self.formatter=(formatter)
    @@formatter = formatter
  end

  def self.formatter
    @@formatter ||= Formatters::Plain
  end

  def self.finders
    @@finders ||= Hash.new(NullFinder)
  end

  finders.merge!({
    "NameError"                           => NameErrorFinders,
    "ActiveRecord::UnknownAttributeError" => SimilarAttributeFinder,
    "ActiveModel::UnknownAttributeError"  => SimilarAttributeFinder,
  })

  case RUBY_ENGINE
  when 'ruby', 'jruby'
    finders["NoMethodError"] = SimilarMethodFinder
  when 'rbx'
    finders["NoMethodError"] =
      if (___ rescue $!).class.to_s == "NameError" # For rbx > 2.5.0
        SimilarMethodFinder
      else
        SimilarMethodFinder::RubiniusSupport       # For rbx < 2.5.0
      end
{'fraction_non_alphanumeric': 0.10686528497409327, 'fraction_numerical': 0.0045336787564766836, 'mean_word_length': 3.272475795297372, 'pattern_counts': {'":': 0, '<': 5, '<?xml version=': 0, '>': 12, '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': '5789071', 'n_tokens_mistral': 1034, 'n_tokens_neox': 977, 'n_words': 226}