grub 0.0.1

Sign up to get free protection for your applications and to get access to all the features.
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 40e937ffd04fdb2cf67a2c9fc765a402e54142df
4
+ data.tar.gz: 4eba708a3e8b9784a9772db961b9310a302cc692
5
+ SHA512:
6
+ metadata.gz: f4043ba1b3ac1b489331bed1325011bcfe68333461b52f1819174781bb43ae68801c3b85ec35e6217fdc320fc3dd6d7b3dd624f0c733daaa6ace66ae9f1bdada
7
+ data.tar.gz: cca141c3cd9efeab215408db737a827664ada4e456877b7d6a8cd8bc197fd3fec1e2a1752076412900b3383f297d6c6ebdc252755da2159aa6b9c76281a7b4b6
@@ -0,0 +1,14 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+ *.bundle
11
+ *.so
12
+ *.o
13
+ *.a
14
+ mkmf.log
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in grub.gemspec
4
+ gemspec
@@ -0,0 +1,22 @@
1
+ Copyright (c) 2016 Ivan Tse
2
+
3
+ MIT License
4
+
5
+ Permission is hereby granted, free of charge, to any person obtaining
6
+ a copy of this software and associated documentation files (the
7
+ "Software"), to deal in the Software without restriction, including
8
+ without limitation the rights to use, copy, modify, merge, publish,
9
+ distribute, sublicense, and/or sell copies of the Software, and to
10
+ permit persons to whom the Software is furnished to do so, subject to
11
+ the following conditions:
12
+
13
+ The above copyright notice and this permission notice shall be
14
+ included in all copies or substantial portions of the Software.
15
+
16
+ THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND,
17
+ EXPRESS OR IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF
18
+ MERCHANTABILITY, FITNESS FOR A PARTICULAR PURPOSE AND
19
+ NONINFRINGEMENT. IN NO EVENT SHALL THE AUTHORS OR COPYRIGHT HOLDERS BE
20
+ LIABLE FOR ANY CLAIM, DAMAGES OR OTHER LIABILITY, WHETHER IN AN ACTION
21
+ OF CONTRACT, TORT OR OTHERWISE, ARISING FROM, OUT OF OR IN CONNECTION
22
+ WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN THE SOFTWARE.
@@ -0,0 +1,31 @@
1
+ # Grub
2
+
3
+ TODO: Write a gem description
4
+
5
+ ## Installation
6
+
7
+ Add this line to your application's Gemfile:
8
+
9
+ ```ruby
10
+ gem 'grub'
11
+ ```
12
+
13
+ And then execute:
14
+
15
+ $ bundle
16
+
17
+ Or install it yourself as:
18
+
19
+ $ gem install grub
20
+
21
+ ## Usage
22
+
23
+ TODO: Write usage instructions here
24
+
25
+ ## Contributing
26
+
27
+ 1. Fork it ( https://github.com/[my-github-username]/grub/fork )
28
+ 2. Create your feature branch (`git checkout -b my-new-feature`)
29
+ 3. Commit your changes (`git commit -am 'Add some feature'`)
30
+ 4. Push to the branch (`git push origin my-new-feature`)
31
+ 5. Create a new Pull Request
@@ -0,0 +1,2 @@
1
+ require "bundler/gem_tasks"
2
+
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ $:.unshift(File.join(File.dirname(__FILE__), "../lib"))
4
+
5
+ require "grub/cli"
6
+ require "grub"
7
+
8
+ Grub::CLI.new.run(ARGV)
@@ -0,0 +1,26 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'grub/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "grub"
8
+ spec.version = Grub::VERSION
9
+ spec.authors = ["Ivan Tse"]
10
+ spec.email = ["ivan.tse1@gmail.com"]
11
+ spec.summary = %q{Add comments to your Gemfile with each dependency's description.}
12
+ spec.description = <<-DESCRIPTION.gsub(/^\s+/, "").gsub(/\n/, " ")
13
+ Clarify your dependencies by adding a detailed comment to each line in Gemfile specifying the
14
+ gem's summary and its website if any.
15
+ DESCRIPTION
16
+ spec.homepage = "https://github.com/ivantsepp/grub"
17
+ spec.license = "MIT"
18
+
19
+ spec.files = `git ls-files -z`.split("\x0")
20
+ spec.executables = spec.files.grep(%r{^bin/}) { |f| File.basename(f) }
21
+ spec.test_files = spec.files.grep(%r{^(test|spec|features)/})
22
+ spec.require_paths = ["lib"]
23
+
24
+ spec.add_runtime_dependency "bundler", "~> 1.7"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ end
@@ -0,0 +1,8 @@
1
+ require "grub/version"
2
+ require "bundler"
3
+ require "grub/gem_line"
4
+ require "grub/gemfile"
5
+ require "grub/spec_finder"
6
+
7
+ module Grub
8
+ end
@@ -0,0 +1,13 @@
1
+ module Grub
2
+ class CLI
3
+ def run(*args)
4
+ Bundler.configure
5
+ gemfile = Gemfile.new
6
+ gemfile.parse
7
+ unless gemfile.gem_lines.empty?
8
+ SpecFinder.new(gemfile.gem_lines).find_specs
9
+ gemfile.write_comments
10
+ end
11
+ end
12
+ end
13
+ end
@@ -0,0 +1,35 @@
1
+ module Grub
2
+ class GemLine
3
+
4
+ attr_accessor :original_line, :location, :prev_line_comment, :name, :spec
5
+
6
+ def initialize(name:, original_line:, location:, prev_line_comment: nil)
7
+ @name = name
8
+ @original_line = original_line
9
+ @location = location
10
+ @prev_line_comment = prev_line_comment
11
+ end
12
+
13
+ def comment
14
+ leading_spaces_count = original_line.length - original_line.lstrip.length
15
+ leading_spaces = original_line[0..leading_spaces_count - 1] if leading_spaces_count > 0
16
+ comment = "# #{description}"
17
+ comment << " (#{website})" unless website.nil? || website.empty?
18
+ comment << "\n"
19
+ "#{leading_spaces}#{comment}"
20
+ end
21
+
22
+ def should_insert?
23
+ prev_line_comment.nil? || !prev_line_comment.include?(comment)
24
+ end
25
+
26
+ def description
27
+ spec.summary if spec
28
+ end
29
+
30
+ def website
31
+ spec.homepage if spec
32
+ end
33
+
34
+ end
35
+ end
@@ -0,0 +1,36 @@
1
+ module Grub
2
+ class Gemfile
3
+
4
+ GEM_LINE_REGEX = /\A\s*gem[\s(]+["']([^'"]*)["']/.freeze
5
+
6
+ attr_accessor :gemfile_path, :gem_lines, :source
7
+
8
+ def initialize(gemfile_path = Bundler.default_gemfile)
9
+ @gemfile_path = gemfile_path
10
+ @source = []
11
+ @gem_lines = []
12
+ end
13
+
14
+ def parse
15
+ self.source = File.readlines(gemfile_path)
16
+ source.each_with_index do |line, i|
17
+ if (match = GEM_LINE_REGEX.match(line))
18
+ prev_line_comment = source[i - 1].strip.start_with?("#") ? source[i - 1] : nil
19
+ self.gem_lines << GemLine.new(
20
+ name: match[1],
21
+ original_line: line,
22
+ location: i,
23
+ prev_line_comment: prev_line_comment
24
+ )
25
+ end
26
+ end
27
+ end
28
+
29
+ def write_comments
30
+ gem_lines.reverse.each do |gem_line|
31
+ source.insert(gem_line.location , gem_line.comment) if gem_line.should_insert?
32
+ end
33
+ File.write(gemfile_path, source.join)
34
+ end
35
+ end
36
+ end
@@ -0,0 +1,32 @@
1
+ module Grub
2
+ class SpecFinder
3
+
4
+ attr_reader :gem_lines
5
+
6
+ def initialize(gem_lines)
7
+ @gem_lines = gem_lines
8
+ end
9
+
10
+ def find_specs
11
+ gem_lines.each do |line|
12
+ matching_specs = Gem::Dependency.new(line.name).matching_specs
13
+ line.spec = matching_specs.first if matching_specs.any?
14
+ end
15
+
16
+ gems_to_fetch = gem_lines.select { |gem_line| gem_line.spec.nil? }
17
+
18
+ if gems_to_fetch.any?
19
+ fetcher = Bundler::Fetcher.new(Gem.sources.first.uri)
20
+ versions, _ = fetcher.send(:fetch_dependency_remote_specs, gems_to_fetch.collect(&:name))
21
+ gems_to_fetch.each do |gem_line|
22
+ print "."
23
+ version = versions.find{ |v| v.first == gem_line.name }[1]
24
+ spec = fetcher.fetch_spec([gem_line.name, version])
25
+ gem_line.spec = spec
26
+ end
27
+ print "\n"
28
+ end
29
+ end
30
+
31
+ end
32
+ end
@@ -0,0 +1,3 @@
1
+ module Grub
2
+ VERSION = "0.0.1"
3
+ end
metadata ADDED
@@ -0,0 +1,87 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: grub
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.0.1
5
+ platform: ruby
6
+ authors:
7
+ - Ivan Tse
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-06 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: bundler
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - "~>"
18
+ - !ruby/object:Gem::Version
19
+ version: '1.7'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - "~>"
25
+ - !ruby/object:Gem::Version
26
+ version: '1.7'
27
+ - !ruby/object:Gem::Dependency
28
+ name: rake
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - "~>"
32
+ - !ruby/object:Gem::Version
33
+ version: '10.0'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.0'
41
+ description: 'Clarify your dependencies by adding a detailed comment to each line
42
+ in Gemfile specifying the gem''s summary and its website if any. '
43
+ email:
44
+ - ivan.tse1@gmail.com
45
+ executables:
46
+ - grub
47
+ extensions: []
48
+ extra_rdoc_files: []
49
+ files:
50
+ - ".gitignore"
51
+ - Gemfile
52
+ - LICENSE.txt
53
+ - README.md
54
+ - Rakefile
55
+ - bin/grub
56
+ - grub.gemspec
57
+ - lib/grub.rb
58
+ - lib/grub/cli.rb
59
+ - lib/grub/gem_line.rb
60
+ - lib/grub/gemfile.rb
61
+ - lib/grub/spec_finder.rb
62
+ - lib/grub/version.rb
63
+ homepage: https://github.com/ivantsepp/grub
64
+ licenses:
65
+ - MIT
66
+ metadata: {}
67
+ post_install_message:
68
+ rdoc_options: []
69
+ require_paths:
70
+ - lib
71
+ required_ruby_version: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - ">="
74
+ - !ruby/object:Gem::Version
75
+ version: '0'
76
+ required_rubygems_version: !ruby/object:Gem::Requirement
77
+ requirements:
78
+ - - ">="
79
+ - !ruby/object:Gem::Version
80
+ version: '0'
81
+ requirements: []
82
+ rubyforge_project:
83
+ rubygems_version: 2.2.2
84
+ signing_key:
85
+ specification_version: 4
86
+ summary: Add comments to your Gemfile with each dependency's description.
87
+ test_files: []