annotate_gemfile 0.1.0

Sign up to get free protection for your applications and to get access to all the features.
checksums.yaml ADDED
@@ -0,0 +1,7 @@
1
+ ---
2
+ SHA1:
3
+ metadata.gz: 6d6df8a2966507b6ef6454428ed6e4a5afc73eb4
4
+ data.tar.gz: 9e0b6e96543613e8c6570db50321359df37b2c42
5
+ SHA512:
6
+ metadata.gz: 399e5caa85e7983443e7e283817eaeb068f226058716835c5deaf0448d61402a8139ff1eba2b78f43703094a217046dbf947b984c185e73b341e77db2eadcedf
7
+ data.tar.gz: 7e2570432a150799dd8336a0aea8da1de6e54d0c990c39f6c07ef2c0515bfd649d62cd98499594f17e5ba1445886bb1d61258a3ad1289524663c2d176c21c7f8
data/.gitignore ADDED
@@ -0,0 +1,9 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,4 @@
1
+ language: ruby
2
+ rvm:
3
+ - 2.1.6
4
+ before_install: gem install bundler -v 1.11.2
data/Gemfile ADDED
@@ -0,0 +1,4 @@
1
+ source 'https://rubygems.org'
2
+
3
+ # Specify your gem's dependencies in annotate_gemfile.gemspec
4
+ gemspec
data/Guardfile ADDED
@@ -0,0 +1,59 @@
1
+ # A sample Guardfile
2
+ # More info at https://github.com/guard/guard#readme
3
+
4
+ ## Uncomment and set this to only include directories you want to watch
5
+ # directories %w(app lib config test spec features) \
6
+ # .select{|d| Dir.exists?(d) ? d : UI.warning("Directory #{d} does not exist")}
7
+
8
+ ## Note: if you are using the `directories` clause above and you are not
9
+ ## watching the project directory ('.'), then you will want to move
10
+ ## the Guardfile to a watched dir and symlink it back, e.g.
11
+ #
12
+ # $ mkdir config
13
+ # $ mv Guardfile config/
14
+ # $ ln -s config/Guardfile .
15
+ #
16
+ # and, you'll have to watch "config/Guardfile" instead of "Guardfile"
17
+
18
+ # Note: The cmd option is now required due to the increasing number of ways
19
+ # rspec may be run, below are examples of the most common uses.
20
+ # * bundler: 'bundle exec rspec'
21
+ # * bundler binstubs: 'bin/rspec'
22
+ # * spring: 'bin/rsspec' (This will use spring if running and you have
23
+ # installed the spring binstubs per the docs)
24
+ # * zeus: 'zeus rspec' (requires the server to be started separetly)
25
+ # * 'just' rspec: 'rspec'
26
+ guard :rspec, cmd: 'bundle exec rspec' do
27
+ watch(%r{^spec/.+_spec\.rb$})
28
+ watch(%r{^lib/(.+)\.rb$}) { |m| "spec/lib/#{m[1]}_spec.rb" }
29
+ watch('spec/spec_helper.rb') { "spec" }
30
+
31
+ # Rails example
32
+ watch(%r{^app/(.+)\.rb$}) { |m| "spec/#{m[1]}_spec.rb" }
33
+ watch(%r{^app/(.*)(\.erb|\.haml|\.slim)$}) { |m| "spec/#{m[1]}#{m[2]}_spec.rb" }
34
+ watch(%r{^app/controllers/(.+)_(controller)\.rb$}) { |m| ["spec/routing/#{m[1]}_routing_spec.rb", "spec/#{m[2]}s/#{m[1]}_#{m[2]}_spec.rb", "spec/acceptance/#{m[1]}_spec.rb"] }
35
+ watch(%r{^spec/support/(.+)\.rb$}) { "spec" }
36
+ watch('config/routes.rb') { "spec/routing" }
37
+ watch('app/controllers/application_controller.rb') { "spec/controllers" }
38
+ watch('spec/rails_helper.rb') { "spec" }
39
+
40
+ # Capybara features specs
41
+ watch(%r{^app/views/(.+)/.*\.(erb|haml|slim)$}) { |m| "spec/features/#{m[1]}_spec.rb" }
42
+
43
+ # Turnip features and steps
44
+ watch(%r{^spec/acceptance/(.+)\.feature$})
45
+ watch(%r{^spec/acceptance/steps/(.+)_steps\.rb$}) { |m| Dir[File.join("**/#{m[1]}.feature")][0] || 'spec/acceptance' }
46
+ end
47
+
48
+
49
+ guard :bundler do
50
+ require 'guard/bundler'
51
+ require 'guard/bundler/verify'
52
+ helper = Guard::Bundler::Verify.new
53
+
54
+ files = ['Gemfile']
55
+ files += Dir['*.gemspec'] if files.any? { |f| helper.uses_gemspec?(f) }
56
+
57
+ # Assume files are symlinked from somewhere
58
+ files.each { |file| watch(helper.real_path(file)) }
59
+ end
data/README.md ADDED
@@ -0,0 +1,27 @@
1
+ [![Build Status](https://travis-ci.org/jakeonrails/annotate_gemfile.svg?branch=master)](https://travis-ci.org/jakeonrails/annotate_gemfile)
2
+
3
+ # AnnotateGemfile
4
+
5
+ This tool will hit the API at Rubygems and get a description for each gem listed in your project's Gemfile, and add that description as a comment above that gem.
6
+
7
+ ## Installation
8
+
9
+ First install the gem:
10
+
11
+ $ gem install annotate_gemfile
12
+
13
+ ## Usage
14
+
15
+ Inside a Ruby project directory with a Gemfile, execute:
16
+
17
+ $ annotate-gemfile
18
+
19
+ ## Development
20
+
21
+ After checking out the repo, run `bin/setup` to install dependencies. Then, run `rake spec` to run the tests. You can also run `bin/console` for an interactive prompt that will allow you to experiment.
22
+
23
+ To install this gem onto your local machine, run `bundle exec rake install`. To release a new version, update the version number in `version.rb`, and then run `bundle exec rake release`, which will create a git tag for the version, push git commits and tags, and push the `.gem` file to [rubygems.org](https://rubygems.org).
24
+
25
+ ## Contributing
26
+
27
+ Bug reports and pull requests are welcome on GitHub at https://github.com/jakeonrails/annotate_gemfile.
data/Rakefile ADDED
@@ -0,0 +1,6 @@
1
+ require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
@@ -0,0 +1,32 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'annotate_gemfile/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "annotate_gemfile"
8
+ spec.version = AnnotateGemfile::VERSION
9
+ spec.authors = ["Jake Moffatt"]
10
+ spec.email = ["jakeonrails@gmail.com"]
11
+
12
+ spec.summary = %q{Adds gem descriptions from Rubygems to every gem in the Gemfile}
13
+ spec.description = %q{Adds gem descriptions from Rubygems to every gem in the Gemfile}
14
+ spec.homepage = "https://github.com/jakeonrails/annotate_gemfile"
15
+
16
+ spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
17
+ spec.bindir = 'bin'
18
+ spec.executables = ['annotate-gemfile']
19
+ spec.require_paths = ["lib"]
20
+
21
+ spec.add_dependency "gems"
22
+ spec.add_dependency "ruby-progressbar"
23
+
24
+ spec.add_development_dependency "bundler", "~> 1.11"
25
+ spec.add_development_dependency "rake", "~> 10.0"
26
+ spec.add_development_dependency "rspec", "~> 3.0"
27
+ spec.add_development_dependency "awesome_print"
28
+ spec.add_development_dependency "guard"
29
+ spec.add_development_dependency "guard-rspec"
30
+ spec.add_development_dependency "guard-bundler"
31
+ spec.add_development_dependency "pry-byebug"
32
+ end
@@ -0,0 +1,7 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "annotate_gemfile"
5
+
6
+ filename = ARGV[0] || 'Gemfile'
7
+ AnnotateGemfile::Annotator.new.annotate(filename)
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "annotate_gemfile"
5
+
6
+ # You can add fixtures and/or initialization code here to make experimenting
7
+ # with your gem easier. You can also use a different console, if you like.
8
+
9
+ # (If you use this, don't forget to add pry to your Gemfile!)
10
+ # require "pry"
11
+ # Pry.start
12
+
13
+ require "irb"
14
+ IRB.start
data/bin/setup ADDED
@@ -0,0 +1,8 @@
1
+ #!/usr/bin/env bash
2
+ set -euo pipefail
3
+ IFS=$'\n\t'
4
+ set -vx
5
+
6
+ bundle install
7
+
8
+ # Do any other automated setup that you need to do here
@@ -0,0 +1,112 @@
1
+ require 'gems'
2
+ require 'ruby-progressbar'
3
+
4
+ require 'awesome_print'
5
+
6
+ module AnnotateGemfile
7
+ class Annotator
8
+
9
+ COMMENT = /^#.*/
10
+ BEGIN_COMMENT = /^=begin/
11
+ END_COMMENT = /^=end/
12
+ GEM_DECLARATION = /^gem\s+/
13
+ GEM_NAME = /gem\s+[('"]([^'")]+)/
14
+ BLANK_LINE = /^\s*$/
15
+
16
+ def initialize
17
+ @block_comment = false
18
+ @progress = ProgressBar.create
19
+ end
20
+
21
+ def annotate(filename)
22
+ lines = File.readlines(filename)
23
+ gem_count = lines.count { |line| line.strip =~ GEM_DECLARATION }
24
+
25
+ @progress = ProgressBar.create(total: gem_count,
26
+ format: '%a %bᗧ%i %p%% %t %c/%C',
27
+ progress_mark: ' ',
28
+ remainder_mark: '・')
29
+
30
+ annotated = annotate_lines(lines)
31
+ File.write("#{filename}.annotated", annotated.join("\n"))
32
+ end
33
+
34
+ def annotate_lines(lines)
35
+ output = lines.each_with_object([]) do |line, output|
36
+ annotated = Array(send(type_of(line), line))
37
+ output.concat annotated
38
+ end.flatten
39
+ output
40
+ end
41
+
42
+ def gem(line)
43
+ [
44
+ describe_gem(line),
45
+ line,
46
+ '',
47
+ ].compact.flatten.tap { @progress.increment }
48
+ end
49
+
50
+ def blank(line)
51
+ line.gsub("\n", '')
52
+ end
53
+
54
+ def comment(line)
55
+ line.gsub("\n", '')
56
+ end
57
+
58
+ def unknown(line)
59
+ line.gsub("\n", '')
60
+ end
61
+
62
+ def describe_gem(line)
63
+ indent = line[/\s*/].to_s
64
+ comment = indent + '# '
65
+ line_width = 80 - comment.length
66
+
67
+ gem_name = line[GEM_NAME, 1]
68
+ return unless description = gem_info_for(gem_name)
69
+ description = word_wrap(description, line_width).split("\n")
70
+ description.map {|d| comment + d.to_s }
71
+ end
72
+
73
+ def gem_info_for(gem_name)
74
+ return unless info = Gems.info(gem_name)
75
+ comment = info['info']
76
+ comment += " (#{info['source_code_uri']})" if info['source_code_uri']
77
+ comment
78
+ end
79
+
80
+ def word_wrap(text, line_width)
81
+ squish(text).split("\n").map do |line|
82
+ line.length > line_width ? line.gsub(/(.{1,#{line_width}})(\s+|$)/, "\\1\n").strip : line
83
+ end.join
84
+ end
85
+
86
+ def type_of(line)
87
+ stripped = line.strip
88
+ return :comment if @block_comment && stripped !=~ /^=end/
89
+
90
+ case stripped
91
+ when COMMENT
92
+ :comment
93
+ when BEGIN_COMMENT || END_COMMENT
94
+ @block_comment = !@block_comment
95
+ :comment
96
+ when GEM_DECLARATION
97
+ :gem
98
+ when BLANK_LINE
99
+ :blank
100
+ else
101
+ :unknown
102
+ end
103
+ end
104
+
105
+ def squish(text)
106
+ text.gsub(/\A[[:space:]]+/, '')
107
+ .gsub(/[[:space:]]+\z/, '')
108
+ .gsub(/[[:space:]]+/, ' ')
109
+ end
110
+
111
+ end
112
+ end
@@ -0,0 +1,3 @@
1
+ module AnnotateGemfile
2
+ VERSION = "0.1.0"
3
+ end
@@ -0,0 +1,5 @@
1
+ require "annotate_gemfile/version"
2
+ require 'annotate_gemfile/annotator'
3
+
4
+ module AnnotateGemfile
5
+ end
metadata ADDED
@@ -0,0 +1,198 @@
1
+ --- !ruby/object:Gem::Specification
2
+ name: annotate_gemfile
3
+ version: !ruby/object:Gem::Version
4
+ version: 0.1.0
5
+ platform: ruby
6
+ authors:
7
+ - Jake Moffatt
8
+ autorequire:
9
+ bindir: bin
10
+ cert_chain: []
11
+ date: 2016-04-23 00:00:00.000000000 Z
12
+ dependencies:
13
+ - !ruby/object:Gem::Dependency
14
+ name: gems
15
+ requirement: !ruby/object:Gem::Requirement
16
+ requirements:
17
+ - - ">="
18
+ - !ruby/object:Gem::Version
19
+ version: '0'
20
+ type: :runtime
21
+ prerelease: false
22
+ version_requirements: !ruby/object:Gem::Requirement
23
+ requirements:
24
+ - - ">="
25
+ - !ruby/object:Gem::Version
26
+ version: '0'
27
+ - !ruby/object:Gem::Dependency
28
+ name: ruby-progressbar
29
+ requirement: !ruby/object:Gem::Requirement
30
+ requirements:
31
+ - - ">="
32
+ - !ruby/object:Gem::Version
33
+ version: '0'
34
+ type: :runtime
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - ">="
39
+ - !ruby/object:Gem::Version
40
+ version: '0'
41
+ - !ruby/object:Gem::Dependency
42
+ name: bundler
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '1.11'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '1.11'
55
+ - !ruby/object:Gem::Dependency
56
+ name: rake
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '10.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '10.0'
69
+ - !ruby/object:Gem::Dependency
70
+ name: rspec
71
+ requirement: !ruby/object:Gem::Requirement
72
+ requirements:
73
+ - - "~>"
74
+ - !ruby/object:Gem::Version
75
+ version: '3.0'
76
+ type: :development
77
+ prerelease: false
78
+ version_requirements: !ruby/object:Gem::Requirement
79
+ requirements:
80
+ - - "~>"
81
+ - !ruby/object:Gem::Version
82
+ version: '3.0'
83
+ - !ruby/object:Gem::Dependency
84
+ name: awesome_print
85
+ requirement: !ruby/object:Gem::Requirement
86
+ requirements:
87
+ - - ">="
88
+ - !ruby/object:Gem::Version
89
+ version: '0'
90
+ type: :development
91
+ prerelease: false
92
+ version_requirements: !ruby/object:Gem::Requirement
93
+ requirements:
94
+ - - ">="
95
+ - !ruby/object:Gem::Version
96
+ version: '0'
97
+ - !ruby/object:Gem::Dependency
98
+ name: guard
99
+ requirement: !ruby/object:Gem::Requirement
100
+ requirements:
101
+ - - ">="
102
+ - !ruby/object:Gem::Version
103
+ version: '0'
104
+ type: :development
105
+ prerelease: false
106
+ version_requirements: !ruby/object:Gem::Requirement
107
+ requirements:
108
+ - - ">="
109
+ - !ruby/object:Gem::Version
110
+ version: '0'
111
+ - !ruby/object:Gem::Dependency
112
+ name: guard-rspec
113
+ requirement: !ruby/object:Gem::Requirement
114
+ requirements:
115
+ - - ">="
116
+ - !ruby/object:Gem::Version
117
+ version: '0'
118
+ type: :development
119
+ prerelease: false
120
+ version_requirements: !ruby/object:Gem::Requirement
121
+ requirements:
122
+ - - ">="
123
+ - !ruby/object:Gem::Version
124
+ version: '0'
125
+ - !ruby/object:Gem::Dependency
126
+ name: guard-bundler
127
+ requirement: !ruby/object:Gem::Requirement
128
+ requirements:
129
+ - - ">="
130
+ - !ruby/object:Gem::Version
131
+ version: '0'
132
+ type: :development
133
+ prerelease: false
134
+ version_requirements: !ruby/object:Gem::Requirement
135
+ requirements:
136
+ - - ">="
137
+ - !ruby/object:Gem::Version
138
+ version: '0'
139
+ - !ruby/object:Gem::Dependency
140
+ name: pry-byebug
141
+ requirement: !ruby/object:Gem::Requirement
142
+ requirements:
143
+ - - ">="
144
+ - !ruby/object:Gem::Version
145
+ version: '0'
146
+ type: :development
147
+ prerelease: false
148
+ version_requirements: !ruby/object:Gem::Requirement
149
+ requirements:
150
+ - - ">="
151
+ - !ruby/object:Gem::Version
152
+ version: '0'
153
+ description: Adds gem descriptions from Rubygems to every gem in the Gemfile
154
+ email:
155
+ - jakeonrails@gmail.com
156
+ executables:
157
+ - annotate-gemfile
158
+ extensions: []
159
+ extra_rdoc_files: []
160
+ files:
161
+ - ".gitignore"
162
+ - ".rspec"
163
+ - ".travis.yml"
164
+ - Gemfile
165
+ - Guardfile
166
+ - README.md
167
+ - Rakefile
168
+ - annotate_gemfile.gemspec
169
+ - bin/annotate-gemfile
170
+ - bin/console
171
+ - bin/setup
172
+ - lib/annotate_gemfile.rb
173
+ - lib/annotate_gemfile/annotator.rb
174
+ - lib/annotate_gemfile/version.rb
175
+ homepage: https://github.com/jakeonrails/annotate_gemfile
176
+ licenses: []
177
+ metadata: {}
178
+ post_install_message:
179
+ rdoc_options: []
180
+ require_paths:
181
+ - lib
182
+ required_ruby_version: !ruby/object:Gem::Requirement
183
+ requirements:
184
+ - - ">="
185
+ - !ruby/object:Gem::Version
186
+ version: '0'
187
+ required_rubygems_version: !ruby/object:Gem::Requirement
188
+ requirements:
189
+ - - ">="
190
+ - !ruby/object:Gem::Version
191
+ version: '0'
192
+ requirements: []
193
+ rubyforge_project:
194
+ rubygems_version: 2.4.8
195
+ signing_key:
196
+ specification_version: 4
197
+ summary: Adds gem descriptions from Rubygems to every gem in the Gemfile
198
+ test_files: []