/usr/lib/ruby/vendor_ruby/did_you_mean/spell_checkers/name_error_checkers/class_name_checker.rb is in ruby-did-you-mean 1.0.0-2.
This file is owned by root:root, with mode 0o644.
The actual contents of the file can be viewed below.
1 2 3 4 5 6 7 8 9 10 11 12 13 14 15 16 17 18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 34 35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 | # -*- frozen-string-literal: true -*-
require 'delegate'
module DidYouMean
class ClassNameChecker
include SpellCheckable
attr_reader :class_name
def initialize(exception)
@class_name, @receiver = exception.name, exception.receiver
end
def candidates
{class_name => class_names}
end
def class_names
scopes.flat_map do |scope|
scope.constants.map do |c|
ClassName.new(c, scope == Object ? "" : "#{scope}::")
end
end
end
def corrections
super.map(&:full_name)
end
def scopes
@scopes ||= @receiver.to_s.split("::").inject([Object]) do |_scopes, scope|
_scopes << _scopes.last.const_get(scope)
end.uniq
end
class ClassName < SimpleDelegator
attr :namespace
def initialize(name, namespace = '')
super(name)
@namespace = namespace
end
def full_name
self.class.new("#{namespace}#{__getobj__}")
end
end
private_constant :ClassName
end
end
|