-
Notifications
You must be signed in to change notification settings - Fork 115
/
did_you_mean.rb
69 lines (55 loc) · 1.53 KB
/
did_you_mean.rb
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
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
require "did_you_mean/version"
require "did_you_mean/core_ext/name_error"
require "did_you_mean/spell_checker"
require 'did_you_mean/spell_checkers/name_error_checkers'
require 'did_you_mean/spell_checkers/method_name_checker'
require 'did_you_mean/spell_checkers/key_error_checker'
require 'did_you_mean/spell_checkers/null_checker'
require "did_you_mean/formatters/plain_formatter"
module DidYouMean
class DeprecatedIgnoredCallers < Array
%i(
+
<<
[]=
insert
unshift
push
).each do |method_name|
eval <<-RUBY, nil, __FILE__, __LINE__ + 1
def #{method_name}(*)
warn "IGNORED_CALLERS has been deprecated and has no effect."
super
end
RUBY
end
end
IGNORED_CALLERS = DeprecatedIgnoredCallers.new
SPELL_CHECKERS = Hash.new(NullChecker)
SPELL_CHECKERS.merge!({
"NameError" => NameErrorCheckers,
"NoMethodError" => MethodNameChecker,
"KeyError" => KeyErrorChecker
})
NameError.prepend DidYouMean::Correctable
KeyError.prepend DidYouMean::Correctable
def self.formatter
@@formatter
end
def self.formatter=(formatter)
@@formatter = formatter
end
self.formatter = PlainFormatter.new
# Deprecated formatter
class Formatter #:nodoc:
def initialize(corrections = [])
@corrections = corrections
end
def to_s
return "" if @corrections.empty?
output = "\nDid you mean? ".dup
output << @corrections.join("\n ")
end
end
deprecate_constant :Formatter
end