Class: DidYouMean::ClassNameChecker

Inherits:
Object
  • Object
show all
Defined in:
lib/did_you_mean/spell_checkers/name_error_checkers/class_name_checker.rb

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(exception) ⇒ ClassNameChecker

Returns a new instance of ClassNameChecker.



9
10
11
# File 'lib/did_you_mean/spell_checkers/name_error_checkers/class_name_checker.rb', line 9

def initialize(exception)
  @class_name, @receiver = exception.name, exception.receiver
end

Instance Attribute Details

#class_nameObject (readonly)

Returns the value of attribute class_name.



7
8
9
# File 'lib/did_you_mean/spell_checkers/name_error_checkers/class_name_checker.rb', line 7

def class_name
  @class_name
end

Instance Method Details

#class_namesObject



17
18
19
20
21
22
23
# File 'lib/did_you_mean/spell_checkers/name_error_checkers/class_name_checker.rb', line 17

def class_names
  scopes.flat_map do |scope|
    scope.constants.map do |c|
      ClassName.new(c, scope == Object ? "" : "#{scope}::")
    end
  end
end

#correctionsObject



13
14
15
# File 'lib/did_you_mean/spell_checkers/name_error_checkers/class_name_checker.rb', line 13

def corrections
  @corrections ||= SpellChecker.new(dictionary: class_names).correct(class_name).map(&:full_name)
end

#scopesObject



25
26
27
28
29
# File 'lib/did_you_mean/spell_checkers/name_error_checkers/class_name_checker.rb', line 25

def scopes
  @scopes ||= @receiver.to_s.split("::").inject([Object]) do |_scopes, scope|
    _scopes << _scopes.last.const_get(scope)
  end.uniq
end