Module: RSpecTracer::Configuration::DslTypoSuggester
- Defined in:
- lib/rspec_tracer/configuration.rb
Overview
Helpers for the DSL-typo ‘did you mean` surface. Lives in a dedicated module so its methods stay outside the configure-time `alias_method :“_#name”` wrapper loop in `Configuration#configure` (which iterates Configuration’s ‘private_instance_methods(false)` twice during `load_default_config` + `load_local_config` and would double-alias any helper instance methods we kept here).
Class Method Summary collapse
-
.candidates ⇒ Object
private
Internal helper for the tracer pipeline.
-
.nearest(typed, candidates) ⇒ Object
private
Internal helper for the tracer pipeline.
Class Method Details
.candidates ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Internal helper for the tracer pipeline.
1439 1440 1441 1442 1443 1444 1445 1446 1447 1448 1449 1450 |
# File 'lib/rspec_tracer/configuration.rb', line 1439 def self.candidates # Strip one or more leading `_` to canonicalize through the # configure wrapper's aliasing levels (single underscore after # one configure, double after two, etc.). RSpecTracer.private_methods(true).each_with_object([]) do |m, acc| s = m.to_s next unless s.start_with?('_') next if s.end_with?('=') acc << s.sub(/\A_+/, '') end.uniq end |
.nearest(typed, candidates) ⇒ Object
This method is part of a private API. You should avoid using this method if possible, as it may be removed or be changed in the future.
Internal helper for the tracer pipeline.
1454 1455 1456 1457 1458 1459 1460 1461 1462 1463 1464 |
# File 'lib/rspec_tracer/configuration.rb', line 1454 def self.nearest(typed, candidates) prefix_match = candidates .select { |c| typed.start_with?(c) || c.start_with?(typed) } .max_by(&:length) return prefix_match if prefix_match require 'did_you_mean' ::DidYouMean::SpellChecker.new(dictionary: candidates).correct(typed).first rescue LoadError nil end |