grub 0.0.6 → 0.0.7
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- data/Gemfile +1 -0
- data/README.md +46 -11
- data/lib/grub/cli.rb +3 -3
- data/lib/grub/gem_line.rb +1 -1
- data/lib/grub/spec_finder.rb +6 -5
- data/lib/grub/version.rb +1 -1
- data/test/grub/gem_line_test.rb +5 -0
- data/test/grub/spec_finder_test.rb +21 -1
- metadata +2 -2
checksums.yaml
CHANGED
@@ -1,7 +1,7 @@
|
|
1
1
|
---
|
2
2
|
SHA1:
|
3
|
-
metadata.gz:
|
4
|
-
data.tar.gz:
|
3
|
+
metadata.gz: 306499cfdaa4d796bba7cfcb5104912e73db4601
|
4
|
+
data.tar.gz: a7ba997f3eaba6b7339625e2f8b34fe16fcedc4d
|
5
5
|
SHA512:
|
6
|
-
metadata.gz:
|
7
|
-
data.tar.gz:
|
6
|
+
metadata.gz: e67ad918f019680c8adf272258be4cf2d6188ca07481192a0d49db465295fe9fcb0ea3c0cb6c3aaf171722dd616e95d0d4b2ce5e4e37f4b41d6c6271fb15b8e8
|
7
|
+
data.tar.gz: 20b025bdd744295afebb01347d92881a72155d340e839a0fb73b99f8e4dd48e4f3048ea11da7e98b1290f5dd33eac94ad2763180de72f54e17a8df9fede16c9a
|
data/Gemfile
CHANGED
data/README.md
CHANGED
@@ -1,30 +1,65 @@
|
|
1
1
|
# Grub
|
2
2
|
|
3
|
-
|
3
|
+
`grub` is command line tool that will add useful comments to your Gemfile. For each gem, `grub` will create a comment with the gem's description and the gem's website. For example, a Gemfile containing the following
|
4
4
|
|
5
|
-
|
5
|
+
```ruby
|
6
|
+
gem "rails"
|
7
|
+
gem "nokogiri"
|
8
|
+
gem "brakeman"
|
9
|
+
```
|
6
10
|
|
7
|
-
|
11
|
+
will be converted into something that is more descriptive and is self-documenting:
|
8
12
|
|
9
13
|
```ruby
|
10
|
-
|
14
|
+
# Full-stack web application framework. (http://www.rubyonrails.org)
|
15
|
+
gem "rails"
|
16
|
+
# Nokogiri (鋸) is an HTML, XML, SAX, and Reader parser (http://nokogiri.org)
|
17
|
+
gem "nokogiri"
|
18
|
+
# Security vulnerability scanner for Ruby on Rails. (http://brakemanscanner.org)
|
19
|
+
gem "brakeman"
|
11
20
|
```
|
12
21
|
|
13
|
-
|
22
|
+
The motivation for `grub` is that developers often open a Gemfile and not know what many of the listed gems are actually for. It's hard to track down which gem is providing which functionality. This is a common problem since many gem names do not reflect the actual feature.
|
14
23
|
|
15
|
-
|
16
|
-
|
17
|
-
Or install it yourself as:
|
24
|
+
## Installation
|
18
25
|
|
19
|
-
|
26
|
+
```
|
27
|
+
$ gem install grub
|
28
|
+
```
|
20
29
|
|
21
30
|
## Usage
|
22
31
|
|
23
|
-
|
32
|
+
Running `grub` itself will add comments to the current directory's `Gemfile`.
|
33
|
+
|
34
|
+
```
|
35
|
+
$ cat Gemfile
|
36
|
+
source 'https://rubygems.org'
|
37
|
+
|
38
|
+
# Specify your gem's dependencies in grub.gemspec
|
39
|
+
gemspec
|
40
|
+
|
41
|
+
gem "pry"
|
42
|
+
$ grub
|
43
|
+
$ cat Gemfile
|
44
|
+
source 'https://rubygems.org'
|
45
|
+
|
46
|
+
# Specify your gem's dependencies in grub.gemspec
|
47
|
+
gemspec
|
48
|
+
|
49
|
+
# An IRB alternative and runtime developer console (http://pryrepl.org)
|
50
|
+
gem "pry"
|
51
|
+
```
|
52
|
+
|
53
|
+
`grub` has several options and you can see them via `grub -h`. `grub` also works with specifying a single gem name:
|
54
|
+
|
55
|
+
```
|
56
|
+
$ grub aasm
|
57
|
+
State machine mixin for Ruby objects (https://github.com/aasm/aasm)
|
58
|
+
```
|
24
59
|
|
25
60
|
## Contributing
|
26
61
|
|
27
|
-
1. Fork it ( https://github.com/
|
62
|
+
1. Fork it ( https://github.com/ivantsepp/grub/fork )
|
28
63
|
2. Create your feature branch (`git checkout -b my-new-feature`)
|
29
64
|
3. Commit your changes (`git commit -am 'Add some feature'`)
|
30
65
|
4. Push to the branch (`git push origin my-new-feature`)
|
data/lib/grub/cli.rb
CHANGED
@@ -32,10 +32,10 @@ module Grub
|
|
32
32
|
|
33
33
|
private
|
34
34
|
|
35
|
-
def print_progress(
|
36
|
-
print "Fetching gem metadata..." if
|
35
|
+
def print_progress(processing, total)
|
36
|
+
print "Fetching gem metadata..." if processing.zero?
|
37
37
|
print "."
|
38
|
-
print "\n" if
|
38
|
+
print "\n" if processing == total
|
39
39
|
end
|
40
40
|
end
|
41
41
|
end
|
data/lib/grub/gem_line.rb
CHANGED
data/lib/grub/spec_finder.rb
CHANGED
@@ -12,26 +12,27 @@ module Grub
|
|
12
12
|
def find_matching_specs_for(gem_lines)
|
13
13
|
gem_lines.each do |line|
|
14
14
|
matching_specs = Gem::Dependency.new(line.name).matching_specs
|
15
|
-
# need to find latest
|
15
|
+
# TODO: need to find latest
|
16
16
|
line.spec = matching_specs.first if matching_specs.any?
|
17
17
|
end
|
18
18
|
end
|
19
19
|
|
20
20
|
def fetch_specs_for(gem_lines)
|
21
21
|
total = gem_lines.length
|
22
|
-
|
23
|
-
yield
|
22
|
+
processing = 0
|
23
|
+
yield processing, total if block_given?
|
24
|
+
# TODO: Support private sources
|
24
25
|
remote = Bundler::Source::Rubygems::Remote.new(Gem.sources.first.uri)
|
25
26
|
fetcher = Bundler::Fetcher.new(remote)
|
26
27
|
dependency_fetcher = fetcher.fetchers.find {|f| Bundler::Fetcher::Dependency === f }
|
27
28
|
versions, _ = dependency_fetcher.dependency_specs(gem_lines.collect(&:name))
|
28
29
|
gem_lines.each do |gem_line|
|
30
|
+
processing += 1
|
31
|
+
yield processing, total if block_given?
|
29
32
|
gem_versions = versions.select { |v| v.first == gem_line.name }
|
30
33
|
next if gem_versions.empty? # couldn't find version on RubyGems so go to next one
|
31
34
|
version = find_latest_version(gem_versions)
|
32
35
|
gem_line.spec = fetcher.fetch_spec([gem_line.name, version])
|
33
|
-
completed += 1
|
34
|
-
yield completed, total if block_given?
|
35
36
|
end
|
36
37
|
end
|
37
38
|
|
data/lib/grub/version.rb
CHANGED
data/test/grub/gem_line_test.rb
CHANGED
@@ -29,6 +29,11 @@ class Grub::GemLineTest < Minitest::Test
|
|
29
29
|
refute gem_line.should_insert?
|
30
30
|
end
|
31
31
|
|
32
|
+
def test_should_insert_with_no_spec
|
33
|
+
gem_line = create_gem_line
|
34
|
+
refute gem_line.should_insert?
|
35
|
+
end
|
36
|
+
|
32
37
|
def test_should_insert_with_already_added_comment
|
33
38
|
gem_line = create_gem_line(prev_line_comment: "# Hello world (http://example.com)\n")
|
34
39
|
spec = stub(summary: "Hello world", homepage: "http://example.com")
|
@@ -44,7 +44,27 @@ class Grub::SpecFinderTest < Minitest::Test
|
|
44
44
|
Grub::SpecFinder.expects(:find_latest_version).returns(Gem::Version.new("1")).twice
|
45
45
|
Bundler::Fetcher.any_instance.expects(:fetch_spec).with(["1", Gem::Version.new("1")]).returns(spec_1)
|
46
46
|
Bundler::Fetcher.any_instance.expects(:fetch_spec).with(["2", Gem::Version.new("1")]).returns(spec_2)
|
47
|
-
|
47
|
+
yielded_values = []
|
48
|
+
Grub::SpecFinder.fetch_specs_for([gem_line_1, gem_line_2]) do |*args|
|
49
|
+
yielded_values << args
|
50
|
+
end
|
51
|
+
assert_equal [[0, 2], [1, 2], [2, 2]], yielded_values
|
52
|
+
$stdout = original_stdout
|
53
|
+
end
|
54
|
+
|
55
|
+
def test_fetch_unknown_specs
|
56
|
+
original_stdout = $stdout
|
57
|
+
$stdout = StringIO.new
|
58
|
+
|
59
|
+
gem_line_1 = mock
|
60
|
+
gem_line_1.stubs(name: "1")
|
61
|
+
gem_line_1.expects(:spec=).never
|
62
|
+
|
63
|
+
dependency_fetcher_mock = Bundler::Fetcher::Dependency.new(nil, nil, nil)
|
64
|
+
Bundler::Fetcher.any_instance.expects(:fetchers).returns([dependency_fetcher_mock])
|
65
|
+
dependency_fetcher_mock.expects(:dependency_specs).with(["1"]).returns([[], "dependencies here"])
|
66
|
+
Bundler::Fetcher.any_instance.expects(:fetch_spec).never
|
67
|
+
Grub::SpecFinder.fetch_specs_for([gem_line_1])
|
48
68
|
|
49
69
|
$stdout = original_stdout
|
50
70
|
end
|
metadata
CHANGED
@@ -1,14 +1,14 @@
|
|
1
1
|
--- !ruby/object:Gem::Specification
|
2
2
|
name: grub
|
3
3
|
version: !ruby/object:Gem::Version
|
4
|
-
version: 0.0.
|
4
|
+
version: 0.0.7
|
5
5
|
platform: ruby
|
6
6
|
authors:
|
7
7
|
- Ivan Tse
|
8
8
|
autorequire:
|
9
9
|
bindir: bin
|
10
10
|
cert_chain: []
|
11
|
-
date: 2016-04-
|
11
|
+
date: 2016-04-27 00:00:00.000000000 Z
|
12
12
|
dependencies:
|
13
13
|
- !ruby/object:Gem::Dependency
|
14
14
|
name: bundler
|