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 CHANGED
@@ -1,7 +1,7 @@
1
1
  ---
2
2
  SHA1:
3
- metadata.gz: fe48faae713a6ecd2906e70df215eab1d9922bc0
4
- data.tar.gz: 732436f1d266fc95011ce8eab373c2a6646f305c
3
+ metadata.gz: 306499cfdaa4d796bba7cfcb5104912e73db4601
4
+ data.tar.gz: a7ba997f3eaba6b7339625e2f8b34fe16fcedc4d
5
5
  SHA512:
6
- metadata.gz: 915a377049972ea359ada3eea8622cdbb3cc646ae075e029c95148c7b398a8f9d22a623eba56c8dd53b2ec28625434a7c0d28206df433188bfd5ccf03e151c3b
7
- data.tar.gz: 331556522d02d6e7ec4c12c6ea7f5a2fbb4d41ff30fa0b1a5d3bf657ee2249cccc73124b958ffe45e7b4da7e467606b2fd4d9539184f9bcda88386518ee1bdbe
6
+ metadata.gz: e67ad918f019680c8adf272258be4cf2d6188ca07481192a0d49db465295fe9fcb0ea3c0cb6c3aaf171722dd616e95d0d4b2ce5e4e37f4b41d6c6271fb15b8e8
7
+ data.tar.gz: 20b025bdd744295afebb01347d92881a72155d340e839a0fb73b99f8e4dd48e4f3048ea11da7e98b1290f5dd33eac94ad2763180de72f54e17a8df9fede16c9a
data/Gemfile CHANGED
@@ -3,4 +3,5 @@ source 'https://rubygems.org'
3
3
  # Specify your gem's dependencies in grub.gemspec
4
4
  gemspec
5
5
 
6
+ # An IRB alternative and runtime developer console (http://pryrepl.org)
6
7
  gem "pry"
data/README.md CHANGED
@@ -1,30 +1,65 @@
1
1
  # Grub
2
2
 
3
- TODO: Write a gem description
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
- ## Installation
5
+ ```ruby
6
+ gem "rails"
7
+ gem "nokogiri"
8
+ gem "brakeman"
9
+ ```
6
10
 
7
- Add this line to your application's Gemfile:
11
+ will be converted into something that is more descriptive and is self-documenting:
8
12
 
9
13
  ```ruby
10
- gem 'grub'
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
- And then execute:
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
- $ bundle
16
-
17
- Or install it yourself as:
24
+ ## Installation
18
25
 
19
- $ gem install grub
26
+ ```
27
+ $ gem install grub
28
+ ```
20
29
 
21
30
  ## Usage
22
31
 
23
- TODO: Write usage instructions here
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/[my-github-username]/grub/fork )
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`)
@@ -32,10 +32,10 @@ module Grub
32
32
 
33
33
  private
34
34
 
35
- def print_progress(completed, total)
36
- print "Fetching gem metadata..." if completed.zero?
35
+ def print_progress(processing, total)
36
+ print "Fetching gem metadata..." if processing.zero?
37
37
  print "."
38
- print "\n" if completed == total
38
+ print "\n" if processing == total
39
39
  end
40
40
  end
41
41
  end
@@ -28,7 +28,7 @@ module Grub
28
28
  end
29
29
 
30
30
  def should_insert?
31
- !info.empty? && !already_added_comment && !existing_comment_option
31
+ !info.strip.empty? && !already_added_comment && !existing_comment_option
32
32
  end
33
33
 
34
34
  private
@@ -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
- completed = 0
23
- yield completed, total if block_given?
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
 
@@ -1,4 +1,4 @@
1
1
  module Grub
2
- VERSION = "0.0.6".freeze
2
+ VERSION = "0.0.7".freeze
3
3
  DESCRIPTION = "Add comments to your Gemfile with each dependency's description.".freeze
4
4
  end
@@ -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
- Grub::SpecFinder.fetch_specs_for([gem_line_1, gem_line_2])
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.6
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-20 00:00:00.000000000 Z
11
+ date: 2016-04-27 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler