Sha256: 8dba832793be6f1ee8f4be6ea7c6deb27431f3ec57f18d67053fc7f140d09c0a
Contents?: true
Size: 1.09 KB
Versions: 1
Compression:
Stored size: 1.09 KB
Contents
# frozen-string-literal: true require_relative "../spell_checker" require_relative "../tree_spell_checker" module DidYouMean class RequirePathChecker attr_reader :path INITIAL_LOAD_PATH = $LOAD_PATH.dup.freeze ENV_SPECIFIC_EXT = ".#{RbConfig::CONFIG["DLEXT"]}" private_constant :INITIAL_LOAD_PATH, :ENV_SPECIFIC_EXT def self.requireables @requireables ||= INITIAL_LOAD_PATH .flat_map {|path| Dir.glob("**/???*{.rb,#{ENV_SPECIFIC_EXT}}", base: path) } .map {|path| path.chomp!(".rb") || path.chomp!(ENV_SPECIFIC_EXT) } end def initialize(exception) @path = exception.path end def corrections @corrections ||= begin threshold = path.size * 2 dictionary = self.class.requireables.reject {|str| str.size >= threshold } spell_checker = path.include?("/") ? TreeSpellChecker : SpellChecker spell_checker.new(dictionary: dictionary).correct(path).uniq end end end end
Version data entries
1 entries across 1 versions & 1 rubygems
Version | Path |
---|---|
did_you_mean-1.5.0 | lib/did_you_mean/spell_checkers/require_path_checker.rb |