did-you-mean 0.1.0 → 0.1.1
This diff represents the content of publicly available package versions that have been released to one of the supported registries. The information contained in this diff is provided for informational purposes only and reflects changes between package versions as they appear in their respective public registries.
- data/VERSION +1 -1
- data/did-you-mean.gemspec +4 -4
- data/lib/did-you-mean.rb +21 -19
- data/spec/did-you-mean_spec.rb +17 -14
- metadata +13 -4
data/VERSION
CHANGED
@@ -1 +1 @@
|
|
1
|
-
0.1.
|
1
|
+
0.1.1
|
data/did-you-mean.gemspec
CHANGED
@@ -5,11 +5,11 @@
|
|
5
5
|
|
6
6
|
Gem::Specification.new do |s|
|
7
7
|
s.name = %q{did-you-mean}
|
8
|
-
s.version = "0.1.
|
8
|
+
s.version = "0.1.1"
|
9
9
|
|
10
10
|
s.required_rubygems_version = Gem::Requirement.new(">= 0") if s.respond_to? :required_rubygems_version=
|
11
11
|
s.authors = ["Leonardo Bessa"]
|
12
|
-
s.date = %q{2010-
|
12
|
+
s.date = %q{2010-08-28}
|
13
13
|
s.description = %q{Did-you-mean compares the misspelled method name with all other method names and suggests the one with closest textual match.}
|
14
14
|
s.email = %q{leobessa@gmail.com}
|
15
15
|
s.extra_rdoc_files = [
|
@@ -32,7 +32,7 @@ Gem::Specification.new do |s|
|
|
32
32
|
s.homepage = %q{http://github.com/leobessa/did-you-mean}
|
33
33
|
s.rdoc_options = ["--charset=UTF-8"]
|
34
34
|
s.require_paths = ["lib"]
|
35
|
-
s.rubygems_version = %q{1.3.
|
35
|
+
s.rubygems_version = %q{1.3.7}
|
36
36
|
s.summary = %q{Runtime corrector for misspelled method calls}
|
37
37
|
s.test_files = [
|
38
38
|
"spec/did-you-mean_spec.rb",
|
@@ -43,7 +43,7 @@ Gem::Specification.new do |s|
|
|
43
43
|
current_version = Gem::Specification::CURRENT_SPECIFICATION_VERSION
|
44
44
|
s.specification_version = 3
|
45
45
|
|
46
|
-
if Gem::Version.new(Gem::
|
46
|
+
if Gem::Version.new(Gem::VERSION) >= Gem::Version.new('1.2.0') then
|
47
47
|
s.add_development_dependency(%q<rspec>, [">= 1.2.9"])
|
48
48
|
s.add_runtime_dependency(%q<levenshtein>, [">= 0.2.0"])
|
49
49
|
else
|
data/lib/did-you-mean.rb
CHANGED
@@ -2,36 +2,38 @@ require 'rubygems'
|
|
2
2
|
require 'levenshtein'
|
3
3
|
|
4
4
|
module DidYouMean
|
5
|
-
|
6
|
-
|
7
|
-
|
8
|
-
|
9
|
-
|
10
|
-
|
11
|
-
|
12
|
-
end
|
5
|
+
|
6
|
+
module ClassMethods
|
7
|
+
def methods_with_a_search
|
8
|
+
methods_array = methods_with_no_search
|
9
|
+
class << methods_array
|
10
|
+
def search(query)
|
11
|
+
self.sort_by {|name| Levenshtein.normalized_distance(name.to_s, query.to_s) }
|
13
12
|
end
|
14
|
-
methods_array
|
15
13
|
end
|
14
|
+
methods_array
|
15
|
+
end
|
16
|
+
end
|
17
|
+
|
18
|
+
def self.included(base)
|
19
|
+
base.class_eval do
|
20
|
+
include DidYouMean::ClassMethods
|
16
21
|
alias_method :methods_with_no_search, :methods
|
17
22
|
alias_method :methods, :methods_with_a_search
|
18
23
|
|
19
|
-
unless method_defined? :method_missing
|
20
|
-
def method_missing(meth, *args, &block); super; end
|
21
|
-
end
|
22
24
|
alias_method :method_missing_without_method_search, :method_missing
|
23
25
|
alias_method :method_missing, :method_missing_with_method_search
|
24
|
-
|
25
26
|
end
|
27
|
+
end
|
26
28
|
|
27
|
-
end
|
28
29
|
def method_missing_with_method_search(name,*args,&block)
|
29
|
-
unless
|
30
|
+
unless self.respond_to? name
|
30
31
|
best_match = self.methods.search(name).first
|
31
|
-
$stdout.print "Did you mean #{self.class}.#{best_match} (
|
32
|
-
response = $stdin.gets
|
33
|
-
return self.send(best_match,*args,&block) if
|
32
|
+
$stdout.print "Did you mean #{self.class}.#{best_match} (Yes/no)?\n"
|
33
|
+
response = $stdin.gets.strip
|
34
|
+
return self.send(best_match,*args,&block) if /\A(yes|y|)\z/i =~ response
|
34
35
|
end
|
35
|
-
method_missing_without_method_search name,*args,&block
|
36
|
+
method_missing_without_method_search name,*args,&block
|
36
37
|
end
|
38
|
+
|
37
39
|
end
|
data/spec/did-you-mean_spec.rb
CHANGED
@@ -23,21 +23,24 @@ describe "DidYouMean" do
|
|
23
23
|
subject do
|
24
24
|
Class.new{include(DidYouMean)}.new
|
25
25
|
end
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
26
|
+
["yes","y",""].each do |answer|
|
27
|
+
it "should suggest methods by textual proximity and call it if develepor types '#{answer}'" do
|
28
|
+
def subject.foo; end
|
29
|
+
$stdout.should_receive(:print).with("Did you mean #{subject.class}.foo (Yes/no)?\n")
|
30
|
+
$stdin.should_receive(:gets).and_return(answer)
|
31
|
+
subject.should_receive(:foo)
|
32
|
+
subject.fo
|
33
|
+
end
|
33
34
|
end
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
40
|
-
|
35
|
+
|
36
|
+
["no","n"].each do |answer|
|
37
|
+
it "should suggest methods by textual proximity and dont call it if develepor types '#{answer}'" do
|
38
|
+
def subject.foo; end
|
39
|
+
$stdout.should_receive(:print).with("Did you mean #{subject.class}.foo (Yes/no)?\n")
|
40
|
+
$stdin.should_receive(:gets).and_return(answer)
|
41
|
+
subject.should_not_receive(:foo)
|
42
|
+
lambda {subject.fo}.should raise_error(NoMethodError)
|
43
|
+
end
|
41
44
|
end
|
42
45
|
|
43
46
|
end
|
metadata
CHANGED
@@ -1,12 +1,13 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: did-you-mean
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
+
hash: 25
|
4
5
|
prerelease: false
|
5
6
|
segments:
|
6
7
|
- 0
|
7
8
|
- 1
|
8
|
-
-
|
9
|
-
version: 0.1.
|
9
|
+
- 1
|
10
|
+
version: 0.1.1
|
10
11
|
platform: ruby
|
11
12
|
authors:
|
12
13
|
- Leonardo Bessa
|
@@ -14,16 +15,18 @@ autorequire:
|
|
14
15
|
bindir: bin
|
15
16
|
cert_chain: []
|
16
17
|
|
17
|
-
date: 2010-
|
18
|
+
date: 2010-08-28 00:00:00 -03:00
|
18
19
|
default_executable:
|
19
20
|
dependencies:
|
20
21
|
- !ruby/object:Gem::Dependency
|
21
22
|
name: rspec
|
22
23
|
prerelease: false
|
23
24
|
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
24
26
|
requirements:
|
25
27
|
- - ">="
|
26
28
|
- !ruby/object:Gem::Version
|
29
|
+
hash: 13
|
27
30
|
segments:
|
28
31
|
- 1
|
29
32
|
- 2
|
@@ -35,9 +38,11 @@ dependencies:
|
|
35
38
|
name: levenshtein
|
36
39
|
prerelease: false
|
37
40
|
requirement: &id002 !ruby/object:Gem::Requirement
|
41
|
+
none: false
|
38
42
|
requirements:
|
39
43
|
- - ">="
|
40
44
|
- !ruby/object:Gem::Version
|
45
|
+
hash: 23
|
41
46
|
segments:
|
42
47
|
- 0
|
43
48
|
- 2
|
@@ -76,23 +81,27 @@ rdoc_options:
|
|
76
81
|
require_paths:
|
77
82
|
- lib
|
78
83
|
required_ruby_version: !ruby/object:Gem::Requirement
|
84
|
+
none: false
|
79
85
|
requirements:
|
80
86
|
- - ">="
|
81
87
|
- !ruby/object:Gem::Version
|
88
|
+
hash: 3
|
82
89
|
segments:
|
83
90
|
- 0
|
84
91
|
version: "0"
|
85
92
|
required_rubygems_version: !ruby/object:Gem::Requirement
|
93
|
+
none: false
|
86
94
|
requirements:
|
87
95
|
- - ">="
|
88
96
|
- !ruby/object:Gem::Version
|
97
|
+
hash: 3
|
89
98
|
segments:
|
90
99
|
- 0
|
91
100
|
version: "0"
|
92
101
|
requirements: []
|
93
102
|
|
94
103
|
rubyforge_project:
|
95
|
-
rubygems_version: 1.3.
|
104
|
+
rubygems_version: 1.3.7
|
96
105
|
signing_key:
|
97
106
|
specification_version: 3
|
98
107
|
summary: Runtime corrector for misspelled method calls
|