123456789_123456789_123456789_123456789_123456789_

Class: DidYouMean::Experimental::IvarNameChecker

Do not use. This class is for internal use only.
Relationships & Source Files
Inherits: Object
Defined in: lib/did_you_mean/experimental/ivar_name_correction.rb

Constant Summary

Class Method Summary

Instance Attribute Summary

Instance Method Summary

Constructor Details

.new(no_method_error, original_checker:) ⇒ IvarNameChecker

[ GitHub ]

  
# File 'lib/did_you_mean/experimental/ivar_name_correction.rb', line 34

def initialize(no_method_error, original_checker: )
  @original_checker = original_checker.new(no_method_error)

  @location   = no_method_error.backtrace_locations.first
  @ivar_names = no_method_error.frame_binding.receiver.instance_variables
end

Instance Attribute Details

#original_checker (readonly)

[ GitHub ]

  
# File 'lib/did_you_mean/experimental/ivar_name_correction.rb', line 32

attr_reader :original_checker

Instance Method Details

#corrections

[ GitHub ]

  
# File 'lib/did_you_mean/experimental/ivar_name_correction.rb', line 41

def corrections
  original_checker.corrections + ivar_name_corrections
end

#ivar_name_corrections

[ GitHub ]

  
# File 'lib/did_you_mean/experimental/ivar_name_correction.rb', line 45

def ivar_name_corrections
  @ivar_name_corrections ||= SpellChecker.new(dictionary: @ivar_names).correct(receiver_name.to_s)
end

#line(abs_path, lineno) (private)

[ GitHub ]

  
# File 'lib/did_you_mean/experimental/ivar_name_correction.rb', line 60

def line(abs_path, lineno)
  if REPLS[abs_path]
    REPLS[abs_path].call
  elsif File.exist?(abs_path)
    File.open(abs_path) do |file|
      file.detect { file.lineno == lineno }
    end
  end
end

#receiver_name (private)

[ GitHub ]

  
# File 'lib/did_you_mean/experimental/ivar_name_correction.rb', line 51

def receiver_name
  return unless @original_checker.receiver.nil?

  abs_path = @location.absolute_path
  lineno   = @location.lineno

  /@(\w+)*\.#{@original_checker.method_name}/ =~ line(abs_path, lineno).to_s && $1
end