autocorrect 0.0.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/.gitignore +4 -0
- data/.rvmrc +49 -0
- data/Gemfile +4 -0
- data/README.markdown +19 -0
- data/Rakefile +2 -0
- data/autocorrect.gemspec +23 -0
- data/lib/autocorrect.rb +3 -0
- data/lib/autocorrect/common.rb +35 -0
- data/lib/autocorrect/insane.rb +31 -0
- data/lib/autocorrect/version.rb +3 -0
- data/lib/autocorrect/whiny.rb +30 -0
- metadata +91 -0
data/.gitignore
ADDED
data/.rvmrc
ADDED
@@ -0,0 +1,49 @@
|
|
1
|
+
#!/usr/bin/env bash
|
2
|
+
|
3
|
+
# This is an RVM Project .rvmrc file, used to automatically load the ruby
|
4
|
+
# development environment upon cd'ing into the directory
|
5
|
+
|
6
|
+
# First we specify our desired <ruby>[@<gemset>], the @gemset name is optional.
|
7
|
+
environment_id="ree-1.8.7-2011.03@autocorrect"
|
8
|
+
|
9
|
+
#
|
10
|
+
# First we attempt to load the desired environment directly from the environment
|
11
|
+
# file. This is very fast and efficicent compared to running through the entire
|
12
|
+
# CLI and selector. If you want feedback on which environment was used then
|
13
|
+
# insert the word 'use' after --create as this triggers verbose mode.
|
14
|
+
#
|
15
|
+
if [[ -d "${rvm_path:-$HOME/.rvm}/environments" \
|
16
|
+
&& -s "${rvm_path:-$HOME/.rvm}/environments/$environment_id" ]] ; then
|
17
|
+
\. "${rvm_path:-$HOME/.rvm}/environments/$environment_id"
|
18
|
+
|
19
|
+
[[ -s ".rvm/hooks/after_use" ]] && . ".rvm/hooks/after_use"
|
20
|
+
else
|
21
|
+
# If the environment file has not yet been created, use the RVM CLI to select.
|
22
|
+
rvm --create "$environment_id"
|
23
|
+
fi
|
24
|
+
|
25
|
+
#
|
26
|
+
# If you use an RVM gemset file to install a list of gems (*.gems), you can have
|
27
|
+
# it be automatically loaded. Uncomment the following and adjust the filename if
|
28
|
+
# necessary.
|
29
|
+
#
|
30
|
+
# filename=".gems"
|
31
|
+
# if [[ -s "$filename" ]] ; then
|
32
|
+
# rvm gemset import "$filename" | grep -v already | grep -v listed | grep -v complete | sed '/^$/d'
|
33
|
+
# fi
|
34
|
+
|
35
|
+
#
|
36
|
+
# If you use bundler and would like to run bundle each time you enter the
|
37
|
+
# directory, you can uncomment the following code.
|
38
|
+
#
|
39
|
+
# # Ensure that Bundler is installed. Install it if it is not.
|
40
|
+
# if ! command -v bundle >/dev/null; then
|
41
|
+
# printf "The rubygem 'bundler' is not installed. Installing it now.\n"
|
42
|
+
# gem install bundler
|
43
|
+
# fi
|
44
|
+
#
|
45
|
+
# # Bundle while reducing excess noise.
|
46
|
+
# printf "Bundling your gems. This may take a few minutes on a fresh clone.\n"
|
47
|
+
# bundle | grep -v '^Using ' | grep -v ' is complete' | sed '/^$/d'
|
48
|
+
#
|
49
|
+
|
data/Gemfile
ADDED
data/README.markdown
ADDED
@@ -0,0 +1,19 @@
|
|
1
|
+
# Autocorrect
|
2
|
+
|
3
|
+
It looks like you mis-spelled that method name. Would you like some help?
|
4
|
+
|
5
|
+
If you want some help in correcting your method name typos when developing a
|
6
|
+
chunk of Ruby code, stick this gem in your project and do:
|
7
|
+
|
8
|
+
require 'autocorrect/whiny'
|
9
|
+
|
10
|
+
If you are utterly, mind-bogglingly insane, you could always do:
|
11
|
+
|
12
|
+
require 'autocorrect/insane'
|
13
|
+
|
14
|
+
and I'll attempt to correct your method name typos for you.
|
15
|
+
|
16
|
+
## Disclaimer
|
17
|
+
|
18
|
+
This is not a serious gem. I had a crazy idea while I was reading Eloquent Ruby
|
19
|
+
and thought I'd try it out. ;-)
|
data/Rakefile
ADDED
data/autocorrect.gemspec
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
# -*- encoding: utf-8 -*-
|
2
|
+
$:.push File.expand_path("../lib", __FILE__)
|
3
|
+
require "autocorrect/version"
|
4
|
+
|
5
|
+
Gem::Specification.new do |s|
|
6
|
+
s.name = "autocorrect"
|
7
|
+
s.version = Autocorrect::VERSION
|
8
|
+
s.platform = Gem::Platform::RUBY
|
9
|
+
s.authors = ["Graeme Mathieson"]
|
10
|
+
s.email = ["mathie@woss.name"]
|
11
|
+
s.homepage = "http://github.com/mathie/autocorrect"
|
12
|
+
s.summary = %q{If you can't spell, or type, your method names we're here to help.}
|
13
|
+
s.description = %q{A crazy gem that 'corrects' your misspelling of method names. Please don't actually use it, I was just testing an idea in my head!}
|
14
|
+
|
15
|
+
s.rubyforge_project = "autocorrect"
|
16
|
+
|
17
|
+
s.add_dependency 'text'
|
18
|
+
|
19
|
+
s.files = `git ls-files`.split("\n")
|
20
|
+
s.test_files = `git ls-files -- {test,spec,features}/*`.split("\n")
|
21
|
+
s.executables = `git ls-files -- bin/*`.split("\n").map{ |f| File.basename(f) }
|
22
|
+
s.require_paths = ["lib"]
|
23
|
+
end
|
data/lib/autocorrect.rb
ADDED
@@ -0,0 +1,35 @@
|
|
1
|
+
require 'text/levenshtein'
|
2
|
+
|
3
|
+
module Autocorrect
|
4
|
+
module Common
|
5
|
+
private
|
6
|
+
def guess_callable_method_for(method, arity)
|
7
|
+
nearest_methods(method).find { |possible_method| [arity, -1].include? method(possible_method).arity }
|
8
|
+
end
|
9
|
+
|
10
|
+
def guess_closest_matched_name_method_for(method)
|
11
|
+
nearest_methods(method)[0]
|
12
|
+
end
|
13
|
+
|
14
|
+
def nearest_methods(method)
|
15
|
+
potential_methods = methods_grouped_by_distance(method)
|
16
|
+
nearest_distance = potential_methods.keys.sort[0]
|
17
|
+
potential_methods[nearest_distance]
|
18
|
+
end
|
19
|
+
|
20
|
+
def methods_grouped_by_distance(method)
|
21
|
+
methods.group_by { |potential_method| Text::Levenshtein.distance(potential_method.to_s, method.to_s) }
|
22
|
+
end
|
23
|
+
|
24
|
+
def print_method_with_args(method, args)
|
25
|
+
"#{method.to_s}(#{args.map { |arg| arg.inspect }.join(", ")})"
|
26
|
+
end
|
27
|
+
|
28
|
+
def raise_method_missing_with_mismatched_args_warning_for(guessed_method, called_method, args, block_present, with_caller = nil)
|
29
|
+
message = "You have called a method that doesn't exist.\n"
|
30
|
+
message << "You tried to call '#{print_method_with_args(called_method, args)}'.\n"
|
31
|
+
message << "We suspect you meant '#{guessed_method}' but you got the number of arguments wrong too (#{method(guessed_method).arity} expected, got #{args.length})."
|
32
|
+
raise NoMethodError, message, with_caller || caller
|
33
|
+
end
|
34
|
+
end
|
35
|
+
end
|
@@ -0,0 +1,31 @@
|
|
1
|
+
require 'autocorrect/common'
|
2
|
+
|
3
|
+
module Autocorrect
|
4
|
+
module Insane
|
5
|
+
include Autocorrect::Common
|
6
|
+
|
7
|
+
def method_missing(method, *args, &block)
|
8
|
+
# Cargo-culted from whiny_nil.rb
|
9
|
+
if method == :to_ary || method == :to_str
|
10
|
+
super
|
11
|
+
elsif guessed_method = guess_callable_method_for(method, args.length)
|
12
|
+
method_missing_warning_for guessed_method, method, args
|
13
|
+
send guessed_method, *args, &block
|
14
|
+
elsif guessed_method = guess_closest_matched_name_method_for(method)
|
15
|
+
raise_method_missing_with_mismatched_args_warning_for guessed_method, method, args, caller
|
16
|
+
else
|
17
|
+
super
|
18
|
+
end
|
19
|
+
end
|
20
|
+
|
21
|
+
private
|
22
|
+
def method_missing_warning_for(guessed_method, called_method, args)
|
23
|
+
message = "You have called a method that doesn't exist.\n"
|
24
|
+
message << "You tried to call '#{print_method_with_args(called_method, args)}'.\n"
|
25
|
+
message << "We suspect you meant '#{print_method_with_args(guessed_method, args)}' and so we're calling it on your behalf."
|
26
|
+
STDERR.puts message
|
27
|
+
end
|
28
|
+
end
|
29
|
+
end
|
30
|
+
|
31
|
+
Object.send :include, Autocorrect::Insane
|
@@ -0,0 +1,30 @@
|
|
1
|
+
require 'autocorrect/common'
|
2
|
+
|
3
|
+
module Autocorrect
|
4
|
+
module Whiny
|
5
|
+
include Autocorrect::Common
|
6
|
+
|
7
|
+
def method_missing(method, *args, &block)
|
8
|
+
# Cargo-culted from whiny_nil.rb
|
9
|
+
if method == :to_ary || method == :to_str
|
10
|
+
super
|
11
|
+
elsif guessed_method = guess_callable_method_for(method, args.length)
|
12
|
+
raise_method_missing_warning_for guessed_method, method, args, caller
|
13
|
+
elsif guessed_method = guess_closest_matched_name_method_for(method)
|
14
|
+
raise_method_missing_with_mismatched_args_warning_for guessed_method, method, args, caller
|
15
|
+
else
|
16
|
+
super
|
17
|
+
end
|
18
|
+
end
|
19
|
+
|
20
|
+
private
|
21
|
+
def raise_method_missing_warning_for(guessed_method, called_method, args, with_caller = nil)
|
22
|
+
message = "You have called a method that doesn't exist.\n"
|
23
|
+
message << "You tried to call '#{print_method_with_args(called_method, args)}'.\n"
|
24
|
+
message << "We suspect you meant '#{print_method_with_args(guessed_method, args)}'.\n"
|
25
|
+
raise NoMethodError, message, with_caller || caller
|
26
|
+
end
|
27
|
+
end
|
28
|
+
end
|
29
|
+
|
30
|
+
Object.send :include, Autocorrect::Whiny
|
metadata
ADDED
@@ -0,0 +1,91 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: autocorrect
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
hash: 29
|
5
|
+
prerelease:
|
6
|
+
segments:
|
7
|
+
- 0
|
8
|
+
- 0
|
9
|
+
- 1
|
10
|
+
version: 0.0.1
|
11
|
+
platform: ruby
|
12
|
+
authors:
|
13
|
+
- Graeme Mathieson
|
14
|
+
autorequire:
|
15
|
+
bindir: bin
|
16
|
+
cert_chain: []
|
17
|
+
|
18
|
+
date: 2011-03-22 00:00:00 +00:00
|
19
|
+
default_executable:
|
20
|
+
dependencies:
|
21
|
+
- !ruby/object:Gem::Dependency
|
22
|
+
name: text
|
23
|
+
prerelease: false
|
24
|
+
requirement: &id001 !ruby/object:Gem::Requirement
|
25
|
+
none: false
|
26
|
+
requirements:
|
27
|
+
- - ">="
|
28
|
+
- !ruby/object:Gem::Version
|
29
|
+
hash: 3
|
30
|
+
segments:
|
31
|
+
- 0
|
32
|
+
version: "0"
|
33
|
+
type: :runtime
|
34
|
+
version_requirements: *id001
|
35
|
+
description: A crazy gem that 'corrects' your misspelling of method names. Please don't actually use it, I was just testing an idea in my head!
|
36
|
+
email:
|
37
|
+
- mathie@woss.name
|
38
|
+
executables: []
|
39
|
+
|
40
|
+
extensions: []
|
41
|
+
|
42
|
+
extra_rdoc_files: []
|
43
|
+
|
44
|
+
files:
|
45
|
+
- .gitignore
|
46
|
+
- .rvmrc
|
47
|
+
- Gemfile
|
48
|
+
- README.markdown
|
49
|
+
- Rakefile
|
50
|
+
- autocorrect.gemspec
|
51
|
+
- lib/autocorrect.rb
|
52
|
+
- lib/autocorrect/common.rb
|
53
|
+
- lib/autocorrect/insane.rb
|
54
|
+
- lib/autocorrect/version.rb
|
55
|
+
- lib/autocorrect/whiny.rb
|
56
|
+
has_rdoc: true
|
57
|
+
homepage: http://github.com/mathie/autocorrect
|
58
|
+
licenses: []
|
59
|
+
|
60
|
+
post_install_message:
|
61
|
+
rdoc_options: []
|
62
|
+
|
63
|
+
require_paths:
|
64
|
+
- lib
|
65
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
66
|
+
none: false
|
67
|
+
requirements:
|
68
|
+
- - ">="
|
69
|
+
- !ruby/object:Gem::Version
|
70
|
+
hash: 3
|
71
|
+
segments:
|
72
|
+
- 0
|
73
|
+
version: "0"
|
74
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
75
|
+
none: false
|
76
|
+
requirements:
|
77
|
+
- - ">="
|
78
|
+
- !ruby/object:Gem::Version
|
79
|
+
hash: 3
|
80
|
+
segments:
|
81
|
+
- 0
|
82
|
+
version: "0"
|
83
|
+
requirements: []
|
84
|
+
|
85
|
+
rubyforge_project: autocorrect
|
86
|
+
rubygems_version: 1.6.1
|
87
|
+
signing_key:
|
88
|
+
specification_version: 3
|
89
|
+
summary: If you can't spell, or type, your method names we're here to help.
|
90
|
+
test_files: []
|
91
|
+
|