rake-typo 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/Gemfile ADDED
@@ -0,0 +1,3 @@
1
+ source :rubygems
2
+
3
+ gemspec
data/LICENSE ADDED
@@ -0,0 +1,21 @@
1
+ (MIT License)
2
+
3
+ Copyright (c) 2013 Adam Prescott <https://aprescott.com/>
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining a copy
6
+ of this software and associated documentation files (the "Software"), to deal
7
+ in the Software without restriction, including without limitation the rights
8
+ to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
9
+ copies of the Software, and to permit persons to whom the Software is
10
+ furnished to do so, subject to the following conditions:
11
+
12
+ The above copyright notice and this permission notice shall be included in
13
+ all copies or substantial portions of the Software.
14
+
15
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
16
+ IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
17
+ FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
18
+ AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
19
+ LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
20
+ OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
21
+ THE SOFTWARE.
data/README.md ADDED
@@ -0,0 +1,43 @@
1
+ # No more task typos
2
+
3
+ Tired of seeing this and not knowing the exact command name?
4
+
5
+ ```
6
+ $ rake ffoo
7
+
8
+ rake aborted!
9
+ Don't know how to build task 'ffoo'
10
+ (See full trace by running task with --trace)
11
+ ```
12
+
13
+ Add this to your rakefile:
14
+
15
+ ```ruby
16
+ require "rake/typo"
17
+ ```
18
+
19
+ Now you can get suggestions for similar task names:
20
+
21
+ ```
22
+ $ rake ffoo
23
+
24
+ Don't know how to build task 'food:bar'
25
+
26
+ Did you mean one of these?
27
+
28
+ foo:bar
29
+ food:bad
30
+ ```
31
+
32
+ # License and contributing
33
+
34
+ Released under the MIT license. See LICENSE for details.
35
+
36
+ Any contributions will be assumed by default to be under the same terms.
37
+
38
+ The quickest way to get changes contributed:
39
+
40
+ 1. Visit the [GitHub repository for rake-typo](https://github.com/aprescott/rake-typo).
41
+ 2. [Fork the repository](https://help.github.com/articles/fork-a-repo).
42
+ 3. Check out a branch on the latest master for your change: `git checkout -b master new-feature` --- do not make changes on `master`! Make sure that anything added or changed has a test in the `test/` directory. Use the existing files as examples. All tests for new/changed behaviour should pass.
43
+ 4. [Send a pull request on GitHub](https://help.github.com/articles/fork-a-repo), including a description of what you've changed. (Note: your contribution will be assumed to be under the same terms of the project by default.)
data/lib/rake/typo.rb ADDED
@@ -0,0 +1,61 @@
1
+ require "rake"
2
+ require "rubyfish"
3
+
4
+ module Rake
5
+ module Typo
6
+ # Finds the Rake::Task instances in +tasks+ that are most
7
+ # similar to +task_name+ and returns a list of them, ordered
8
+ # by name.
9
+ def self.candidate_tasks(task_name, tasks)
10
+ best_similarity = nil
11
+
12
+ distances = tasks.map do |t|
13
+ similarity = RubyFish::DamerauLevenshtein.distance(task_name, t.to_s)
14
+
15
+ # start off with the first distance count we find to be the best
16
+ best_similarity ||= similarity
17
+
18
+ # seek the lowest we can
19
+ best_similarity = similarity if similarity < best_similarity
20
+
21
+ [similarity, t]
22
+ end
23
+
24
+ distances.select! { |sim, name| sim == best_similarity }
25
+ distances.sort_by! { |sim, task| task.name }
26
+ distances.map { |sim, task| task }
27
+ end
28
+ end
29
+ end
30
+
31
+ module Rake::TaskManager
32
+ alias_method :orig_access, :[]
33
+
34
+ # Wrap the `TaskManager#[]` method to capture
35
+ # calls to `#fail` to append possibly misspelled
36
+ # commands.
37
+ def [](*args)
38
+ task_name = args.first
39
+ begin
40
+ orig_access(*args)
41
+ rescue => e
42
+ msg = "#{e}"
43
+
44
+ candidates = Rake::Typo.candidate_tasks(task_name, Rake.application.tasks)
45
+
46
+ unless candidates.empty?
47
+ msg += "\n\n"
48
+ msg += "Did you mean #{candidates.size == 1 ? "this" : "one of these"}?\n\n"
49
+
50
+ candidates.each do |c|
51
+ msg += "\t#{c.name}\n"
52
+ end
53
+ end
54
+
55
+ # abort, not fail as in the original, just
56
+ # to have a friendlier message without a
57
+ # stacktrace.
58
+ abort msg
59
+ end
60
+ end
61
+ end
data/lib/rake_typo.rb ADDED
@@ -0,0 +1 @@
1
+ require "rake/typo"
data/rake-typo.gemspec ADDED
@@ -0,0 +1,17 @@
1
+ Gem::Specification.new do |s|
2
+ s.name = "rake-typo"
3
+ s.version = "0.1"
4
+ s.authors = ["Adam Prescott"]
5
+ s.email = ["adam@aprescott.com"]
6
+ s.homepage = "https://github.com/aprescott/rake-typo"
7
+ s.summary = "Get task suggestions when you mistype Rake tasks."
8
+ s.description = "Provides a list of possible tasks you might have meant when Rake can't find a task you're trying to run."
9
+ s.files = Dir["{lib/**/*,test/**/*}"] + %w[rake-typo.gemspec rakefile LICENSE Gemfile README.md]
10
+ s.require_path = "lib"
11
+ s.test_files = Dir["test/*"]
12
+
13
+ s.add_runtime_dependency("rake", ">= 0.8.7", "< 11.0.0")
14
+ s.add_runtime_dependency("rubyfish", "~> 0.0.5")
15
+
16
+ s.add_development_dependency("rspec", "~> 2.5")
17
+ end
data/rakefile ADDED
@@ -0,0 +1,11 @@
1
+ require "rake"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:test) do |t|
5
+ t.rspec_opts = "-I test --color --format nested"
6
+ t.pattern = "test/**/*_spec.rb"
7
+ t.verbose = false
8
+ t.fail_on_error = true
9
+ end
10
+
11
+ task :default => :test
@@ -0,0 +1 @@
1
+ require "rake/typo"
data/test/typo_spec.rb ADDED
@@ -0,0 +1,27 @@
1
+ require "test_helper.rb"
2
+
3
+ describe Rake::Typo do
4
+ subject { Rake::Typo }
5
+
6
+ def candidates(task_name, names)
7
+ names.map! do |n|
8
+ d = double("")
9
+ d.stub(:name) { n }
10
+ d
11
+ end
12
+
13
+ subject.candidate_tasks(task_name, names)
14
+ end
15
+
16
+ describe ".candidate_tasks" do
17
+ it "meets a few basic requirements" do
18
+ c = candidates("food", %w[foo])
19
+ c.size.should == 1
20
+ c.first.name.should == "foo"
21
+
22
+ c = candidates("food", %w[foo fodo])
23
+ c.size.should == 2
24
+ c.map { |d| d.name }.sort.should == %w[foo fodo].sort
25
+ end
26
+ end
27
+ end
metadata ADDED
@@ -0,0 +1,111 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: rake-typo
3
+ version: !ruby/object:Gem::Version
4
+ version: '0.1'
5
+ prerelease:
6
+ platform: ruby
7
+ authors:
8
+ - Adam Prescott
9
+ autorequire:
10
+ bindir: bin
11
+ cert_chain: []
12
+ date: 2013-03-09 00:00:00.000000000 Z
13
+ dependencies:
14
+ - !ruby/object:Gem::Dependency
15
+ name: rake
16
+ requirement: !ruby/object:Gem::Requirement
17
+ none: false
18
+ requirements:
19
+ - - ! '>='
20
+ - !ruby/object:Gem::Version
21
+ version: 0.8.7
22
+ - - <
23
+ - !ruby/object:Gem::Version
24
+ version: 11.0.0
25
+ type: :runtime
26
+ prerelease: false
27
+ version_requirements: !ruby/object:Gem::Requirement
28
+ none: false
29
+ requirements:
30
+ - - ! '>='
31
+ - !ruby/object:Gem::Version
32
+ version: 0.8.7
33
+ - - <
34
+ - !ruby/object:Gem::Version
35
+ version: 11.0.0
36
+ - !ruby/object:Gem::Dependency
37
+ name: rubyfish
38
+ requirement: !ruby/object:Gem::Requirement
39
+ none: false
40
+ requirements:
41
+ - - ~>
42
+ - !ruby/object:Gem::Version
43
+ version: 0.0.5
44
+ type: :runtime
45
+ prerelease: false
46
+ version_requirements: !ruby/object:Gem::Requirement
47
+ none: false
48
+ requirements:
49
+ - - ~>
50
+ - !ruby/object:Gem::Version
51
+ version: 0.0.5
52
+ - !ruby/object:Gem::Dependency
53
+ name: rspec
54
+ requirement: !ruby/object:Gem::Requirement
55
+ none: false
56
+ requirements:
57
+ - - ~>
58
+ - !ruby/object:Gem::Version
59
+ version: '2.5'
60
+ type: :development
61
+ prerelease: false
62
+ version_requirements: !ruby/object:Gem::Requirement
63
+ none: false
64
+ requirements:
65
+ - - ~>
66
+ - !ruby/object:Gem::Version
67
+ version: '2.5'
68
+ description: Provides a list of possible tasks you might have meant when Rake can't
69
+ find a task you're trying to run.
70
+ email:
71
+ - adam@aprescott.com
72
+ executables: []
73
+ extensions: []
74
+ extra_rdoc_files: []
75
+ files:
76
+ - lib/rake_typo.rb
77
+ - lib/rake/typo.rb
78
+ - test/test_helper.rb
79
+ - test/typo_spec.rb
80
+ - rake-typo.gemspec
81
+ - rakefile
82
+ - LICENSE
83
+ - Gemfile
84
+ - README.md
85
+ homepage: https://github.com/aprescott/rake-typo
86
+ licenses: []
87
+ post_install_message:
88
+ rdoc_options: []
89
+ require_paths:
90
+ - lib
91
+ required_ruby_version: !ruby/object:Gem::Requirement
92
+ none: false
93
+ requirements:
94
+ - - ! '>='
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ required_rubygems_version: !ruby/object:Gem::Requirement
98
+ none: false
99
+ requirements:
100
+ - - ! '>='
101
+ - !ruby/object:Gem::Version
102
+ version: '0'
103
+ requirements: []
104
+ rubyforge_project:
105
+ rubygems_version: 1.8.24
106
+ signing_key:
107
+ specification_version: 3
108
+ summary: Get task suggestions when you mistype Rake tasks.
109
+ test_files:
110
+ - test/test_helper.rb
111
+ - test/typo_spec.rb