Class: DidYouMean::RequirePathChecker
- Inherits:
-
Object
- Object
- DidYouMean::RequirePathChecker
- Defined in:
- lib/did_you_mean/spell_checkers/require_path_checker.rb
Instance Attribute Summary collapse
-
#path ⇒ Object
readonly
Returns the value of attribute path.
Class Method Summary collapse
Instance Method Summary collapse
- #corrections ⇒ Object
-
#initialize(exception) ⇒ RequirePathChecker
constructor
A new instance of RequirePathChecker.
Constructor Details
#initialize(exception) ⇒ RequirePathChecker
Returns a new instance of RequirePathChecker.
25 26 27 |
# File 'lib/did_you_mean/spell_checkers/require_path_checker.rb', line 25 def initialize(exception) @path = exception.path end |
Instance Attribute Details
#path ⇒ Object (readonly)
Returns the value of attribute path.
9 10 11 |
# File 'lib/did_you_mean/spell_checkers/require_path_checker.rb', line 9 def path @path end |
Class Method Details
.requireables ⇒ Object
19 20 21 22 23 |
# File 'lib/did_you_mean/spell_checkers/require_path_checker.rb', line 19 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 |
Instance Method Details
#corrections ⇒ Object
29 30 31 32 33 34 35 36 37 |
# File 'lib/did_you_mean/spell_checkers/require_path_checker.rb', line 29 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 |