Class: DidYouMean::ClassNameChecker
- Inherits:
-
Object
- Object
- DidYouMean::ClassNameChecker
- Defined in:
- lib/did_you_mean/spell_checkers/name_error_checkers/class_name_checker.rb
Instance Attribute Summary collapse
-
#class_name ⇒ Object
readonly
Returns the value of attribute class_name.
Instance Method Summary collapse
- #class_names ⇒ Object
- #corrections ⇒ Object
-
#initialize(exception) ⇒ ClassNameChecker
constructor
A new instance of ClassNameChecker.
- #scopes ⇒ Object
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, @original_message = exception.name, exception.receiver, exception. end |
Instance Attribute Details
#class_name ⇒ Object (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_names ⇒ Object
20 21 22 23 24 25 26 |
# File 'lib/did_you_mean/spell_checkers/name_error_checkers/class_name_checker.rb', line 20 def class_names scopes.flat_map do |scope| scope.constants.map do |c| ClassName.new(c, scope == Object ? "" : "#{scope}::") end end end |
#corrections ⇒ Object
13 14 15 16 17 18 |
# 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) .reject {|qualified_name| @original_message.include?(qualified_name) } end |
#scopes ⇒ Object
28 29 30 31 32 |
# File 'lib/did_you_mean/spell_checkers/name_error_checkers/class_name_checker.rb', line 28 def scopes @scopes ||= @receiver.to_s.split("::").inject([Object]) do |_scopes, scope| _scopes << _scopes.last.const_get(scope) end.uniq end |