class DidYouMean::ClassNameChecker

Attributes

class_name[R]

Public Class Methods

new(exception) click to toggle source
# File lib/did_you_mean/spell_checkers/name_error_checkers/class_name_checker.rb, line 7
def initialize(exception)
  @class_name, @receiver = exception.name, exception.receiver
end

Public Instance Methods

class_names() click to toggle source
# File lib/did_you_mean/spell_checkers/name_error_checkers/class_name_checker.rb, line 15
def class_names
  scopes.flat_map do |scope|
    scope.constants.map do |c|
      ClassName.new(c, scope == Object ? "" : "#{scope}::")
    end
  end
end
corrections() click to toggle source
# File lib/did_you_mean/spell_checkers/name_error_checkers/class_name_checker.rb, line 11
def corrections
  @corrections ||= SpellChecker.new(dictionary: class_names).correct(class_name).map(&:full_name)
end
scopes() click to toggle source
# File lib/did_you_mean/spell_checkers/name_error_checkers/class_name_checker.rb, line 23
def scopes
  @scopes ||= @receiver.to_s.split("::").inject([Object]) do |_scopes, scope|
    _scopes << _scopes.last.const_get(scope)
  end.uniq
end