guessmethod 0.1.1 → 0.1.2
Sign up to get free protection for your applications and to get access to all the features.
- data/History.txt +5 -0
- data/lib/guessmethod.rb +37 -37
- data/lib/guessmethod/version.rb +1 -1
- data/website/index.html +1 -1
- metadata +2 -2
data/History.txt
CHANGED
@@ -1,3 +1,8 @@
|
|
1
|
+
== 0.1.2 2007-11-12
|
2
|
+
|
3
|
+
* GuessMethod and GuessConstant now both try the original method_ or const_missing, capturing the error, before trying. On failure, raises the original error.
|
4
|
+
* Cleaned up error messages now that guessing is a last resort, not a first.
|
5
|
+
|
1
6
|
== 0.1.1 2007-11-08
|
2
7
|
|
3
8
|
* Changed old_const_missing and old_method_missing to the less likely to blow up unguessed_const_missing and unguessed_method_missing
|
data/lib/guessmethod.rb
CHANGED
@@ -32,18 +32,22 @@ module GuessMethod
|
|
32
32
|
|
33
33
|
def guess_method_missing(meth, *args, &block)
|
34
34
|
if GuessMethodOptions[:active]
|
35
|
-
|
36
|
-
case possible_methods.size
|
37
|
-
when 1
|
38
|
-
call_method = possible_methods.first
|
39
|
-
$stderr.puts GuessMethodOutputter.replacing_method(meth, call_method, self)
|
40
|
-
self.send(call_method, *args, &block)
|
41
|
-
when 0
|
42
|
-
$stderr.puts GuessMethodOutputter.no_method_in_threshold(meth, self)
|
43
|
-
unguessed_method_missing(meth, *args, &block)
|
44
|
-
else
|
45
|
-
$stderr.puts GuessMethodOutputter.ambiguous_method(meth, possible_methods, self)
|
35
|
+
begin
|
46
36
|
unguessed_method_missing(meth, *args, &block)
|
37
|
+
rescue NoMethodError, NameError => e
|
38
|
+
possible_methods = GuessMethodGuesser.find_closest(self.methods, meth)
|
39
|
+
case possible_methods.size
|
40
|
+
when 1
|
41
|
+
call_method = possible_methods.first
|
42
|
+
$stderr.puts GuessMethodOutputter.replacing_method(meth, call_method, self)
|
43
|
+
self.send(call_method, *args, &block)
|
44
|
+
when 0
|
45
|
+
$stderr.puts GuessMethodOutputter.no_method_in_threshold(meth, self)
|
46
|
+
raise e
|
47
|
+
else
|
48
|
+
$stderr.puts GuessMethodOutputter.ambiguous_method(meth, possible_methods, self)
|
49
|
+
raise e
|
50
|
+
end
|
47
51
|
end
|
48
52
|
else
|
49
53
|
unguessed_method_missing(meth, *args, &block)
|
@@ -74,20 +78,20 @@ module GuessMethod
|
|
74
78
|
if GuessMethodOptions[:active]
|
75
79
|
begin
|
76
80
|
return unguessed_const_missing(sym)
|
77
|
-
rescue NameError
|
78
|
-
|
79
|
-
|
80
|
-
|
81
|
-
|
82
|
-
|
83
|
-
|
84
|
-
|
85
|
-
|
86
|
-
|
87
|
-
|
88
|
-
|
89
|
-
|
90
|
-
|
81
|
+
rescue NameError => e
|
82
|
+
possible_consts = GuessMethodGuesser.find_closest(self.constants, sym)
|
83
|
+
case possible_consts.size
|
84
|
+
when 1
|
85
|
+
call_const = possible_consts.first
|
86
|
+
$stderr.puts GuessMethodOutputter.replacing_const(sym, call_const, self)
|
87
|
+
self.const_get(call_const)
|
88
|
+
when 0
|
89
|
+
$stderr.puts GuessMethodOutputter.no_const_in_threshold(sym, self)
|
90
|
+
raise e
|
91
|
+
else
|
92
|
+
$stderr.puts GuessMethodOutputter.ambigious_const(sym, possible_consts, self)
|
93
|
+
raise e
|
94
|
+
end
|
91
95
|
end
|
92
96
|
else
|
93
97
|
unguessed_const_missing(sym)
|
@@ -101,7 +105,7 @@ module GuessMethod
|
|
101
105
|
def self.find_closest(haystack, needle)
|
102
106
|
closest_distance = haystack.map {|x| x.to_s.downcase.levenshtein(needle.to_s.downcase,
|
103
107
|
GuessMethodOptions[:insert_weight], GuessMethodOptions[:delete_weight],
|
104
|
-
GuessMethodOptions[:substitution_weight])}.min
|
108
|
+
GuessMethodOptions[:substitution_weight])}.min || 0
|
105
109
|
if closest_distance <= GuessMethodOptions[:threshold]
|
106
110
|
haystack.find_all {|x| x.to_s.downcase.levenshtein(needle.to_s.downcase,
|
107
111
|
GuessMethodOptions[:insert_weight], GuessMethodOptions[:delete_weight],
|
@@ -150,12 +154,10 @@ module GuessMethod
|
|
150
154
|
end
|
151
155
|
|
152
156
|
def self.no_method_in_threshold(meth, obj) #:nodoc:
|
153
|
-
Formatter.color('no method in threshold:', :red) <<
|
154
|
-
' for ' <<
|
157
|
+
Formatter.color('no method in threshold: ', :red) <<
|
155
158
|
Formatter.color(meth, :green) <<
|
156
|
-
'
|
157
|
-
GuessMethodOutputter.object(obj)
|
158
|
-
"'s method_missing"
|
159
|
+
' for ' <<
|
160
|
+
GuessMethodOutputter.object(obj)
|
159
161
|
end
|
160
162
|
|
161
163
|
def self.replacing_method(meth, call_method, obj) #:nodoc:
|
@@ -175,16 +177,14 @@ module GuessMethod
|
|
175
177
|
' possible matches ' <<
|
176
178
|
possibilities.map {|m| Formatter.color(m, :cyan)}.join(', ') <<
|
177
179
|
' for ' <<
|
178
|
-
|
180
|
+
Formatter.color(obj, :green, :bold)
|
179
181
|
end
|
180
182
|
|
181
183
|
def self.no_const_in_threshold(sym, obj) #:nodoc:
|
182
|
-
Formatter.color('no constant in threshold:', :red) <<
|
183
|
-
' for ' <<
|
184
|
+
Formatter.color('no constant in threshold: ', :red) <<
|
184
185
|
Formatter.color(sym, :green) <<
|
185
|
-
'
|
186
|
-
Formatter.color(obj, :green, :bold)
|
187
|
-
"'s const_missing"
|
186
|
+
' for ' <<
|
187
|
+
Formatter.color(obj, :green, :bold)
|
188
188
|
end
|
189
189
|
|
190
190
|
def self.replacing_const(sym, call_const, obj) #:nodoc:
|
data/lib/guessmethod/version.rb
CHANGED
data/website/index.html
CHANGED
@@ -33,7 +33,7 @@
|
|
33
33
|
<h1>Guess Method</h1>
|
34
34
|
<div id="version" class="clickable" onclick='document.location = "http://rubyforge.org/projects/guessmethod"; return false'>
|
35
35
|
<p>Get Version</p>
|
36
|
-
<a href="http://rubyforge.org/projects/guessmethod" class="numbers">0.1.
|
36
|
+
<a href="http://rubyforge.org/projects/guessmethod" class="numbers">0.1.2</a>
|
37
37
|
</div>
|
38
38
|
<h1>→ ‘guessmethod’</h1>
|
39
39
|
|
metadata
CHANGED
@@ -3,8 +3,8 @@ rubygems_version: 0.9.4
|
|
3
3
|
specification_version: 1
|
4
4
|
name: guessmethod
|
5
5
|
version: !ruby/object:Gem::Version
|
6
|
-
version: 0.1.
|
7
|
-
date: 2007-11-
|
6
|
+
version: 0.1.2
|
7
|
+
date: 2007-11-12 00:00:00 -07:00
|
8
8
|
summary: an aggressive spell checker for irb
|
9
9
|
require_paths:
|
10
10
|
- lib
|