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.
1343 1344 1345 1346 1347 1348 1349 1350 1351 1352 1353 1354 |
# File 'lib/rspec_tracer/configuration.rb', line 1343 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.
1358 1359 1360 1361 1362 1363 1364 1365 1366 1367 1368 |
# File 'lib/rspec_tracer/configuration.rb', line 1358 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 |