gem_bench 0.0.8 → 1.0.0

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: 7709c90fcd4cbb3197647d563af1394c48a33f5f
4
- data.tar.gz: a42acb1c16d5aa9271193336d8197d5b40300c35
3
+ metadata.gz: 7363995b8c6c16faf3412019c2b07fb9f93386a3
4
+ data.tar.gz: d8761eae4394fb57c6e93cc31766f7f8025af1cb
5
5
  SHA512:
6
- metadata.gz: f20b735303e993af008611a2321ae6a35fe4ff8f0b28564702c0ad8f33c8b1c583badee4372944bbd6492cd31ea85bf46f668f6c89df1e943410ae59085f7ab0
7
- data.tar.gz: 999ca2bfe06f754e49d9691361963fa5453db09da12c9100caee1cc8ecfe08d079326f0a58919ece3be51536edb1a3e880af4171cf93da2ce0f385a73e83a7e5
6
+ metadata.gz: c9e236ef841b15ae900db8843fe54ea9595a5a7a967fa7d5b68853eab8dc157f01df83029afb2a69d03a67abcb31770d494e5cba720966bc867cd19e1fe06e67
7
+ data.tar.gz: 478fec5276dce61c670eafac339b7d421b62e140164b667e2bc4bcea974e0ad2d29d27b01583c46854413c60ea03c84937fa7e7b1a4a604ca53e09b09eca026c
data/.byebug_history ADDED
@@ -0,0 +1,44 @@
1
+ exit
2
+ instance.check_gemfile?
3
+ instance.check_gemfile
4
+ instance
5
+ exit
6
+ next
7
+ gemfile_lines
8
+ gemfile_trash
9
+ next
10
+ a =~ GemBench::TRASH_REGEX
11
+ a = "gem \"bundler\" # For specs!\n"
12
+ all_lines
13
+ exit
14
+ scout.gemfile_lines
15
+ gemfile_lines
16
+ scout
17
+ next
18
+ exit
19
+ self.gemfile_lines
20
+ scout
21
+ gemfile_lines
22
+ next
23
+ exit
24
+ self.scout.gemfile_lines
25
+ self.gemfile_lines
26
+ @scout.gemfile_lines
27
+ @scout
28
+ @gemfile_lines
29
+ gemfile_lines
30
+ Gem.loaded_specs.values
31
+ next
32
+ Gem.loaded_specs.values
33
+ next
34
+ exit
35
+ next
36
+ @loaded_gems
37
+ loaded_gems
38
+ next
39
+ @gemfile_trash, @gemfile_lines = all_lines.partition {|x| x =~ GemBench::TRASH_REGEX}
40
+ all_lines
41
+ next
42
+ file.readlines
43
+ next
44
+ gemfile_path
data/.gitignore ADDED
@@ -0,0 +1,15 @@
1
+ /.bundle/
2
+ /.yardoc
3
+ /Gemfile.lock
4
+ /_yardoc/
5
+ /coverage/
6
+ /doc/
7
+ /pkg/
8
+ /spec/reports/
9
+ /tmp/
10
+
11
+ # rspec failure tracking
12
+ .rspec_status
13
+
14
+ *.gem
15
+ /.idea/
data/.rspec ADDED
@@ -0,0 +1,2 @@
1
+ --format documentation
2
+ --color
data/.travis.yml ADDED
@@ -0,0 +1,5 @@
1
+ sudo: false
2
+ language: ruby
3
+ rvm:
4
+ - 2.4.0
5
+ before_install: gem install bundler -v 1.14.5
data/CHANGELOG CHANGED
@@ -1,3 +1,10 @@
1
+ Version 1.0.0 - FEB.26.2017
2
+ * New feature: scan all code (except for test/spec/feature code) in all loaded gems for a given regex:
3
+ - puts GemBench.find(look_for_regex: /HERE BE DRAGONS/).starters.map {|gem| "#{gem.name} has DRAGONS at #{gem.stats}" }.join("\n")
4
+ * Added basic specs
5
+ * More Documentation
6
+ * added back git dependency to gemspec (pulled in latest Gem scaffolding from Bundler :/)
7
+
1
8
  Version 0.0.8 - JAN.16.2014
2
9
  * Corrected issues with 0.0.7 release.
3
10
  * More Documentation
data/Gemfile ADDED
@@ -0,0 +1,6 @@
1
+ source 'https://rubygems.org'
2
+
3
+ gem "bundler" # For specs!
4
+
5
+ # Specify your gem's dependencies in gem_bench.gemspec
6
+ gemspec
data/README.md CHANGED
@@ -1,13 +1,51 @@
1
- # GemBench
1
+ # GemBench [![Inline docs](http://inch-ci.org/github/pboling/gem_bench.png)](http://inch-ci.org/github/pboling/gem_bench)
2
+
3
+ `gem_bench` is the super easy way to trim down app load times by keeping your worst players on the bench.
2
4
 
3
5
  Gem: "Put me in coach!"
4
6
  You: ❨╯°□°❩╯︵┻━┻
5
7
 
6
- `gem_bench` is the super easy way to trim down app load times by keeping your worst players on the bench.
8
+ The new feature for 1.0.0 release allows you to search the Ruby code of all your gems for a specified regex, to find out which gems have wat DRAGONS.
9
+
10
+ Gem: "I have no wat DRAGONS!"
11
+ You: ❨╯°□°❩╯︵┻━┻
12
+
13
+ ```
14
+ >> puts GemBench.find(look_for_regex: /wat/).starters.map {|gem| "#{gem.name} has wat DRAGONS at #{gem.stats}" }.join("\n")
15
+ [GemBench] Will search for gems in ["/Users/pboling/.rvm/gems/ruby-2.4.0@foss/gems", "/Users/pboling/.rvm/gems/ruby-2.4.0@global/gems", "/Users/pboling/.rvm/gems/ruby-2.4.0@foss/bundler/gems"]
16
+ [GemBench] Detected 11 loaded gems + 2 loaded gems which GemBench is configured to ignore.
17
+ byebug has wat DRAGONS at [["/Users/pboling/.rvm/gems/ruby-2.4.0@foss/gems/byebug-9.0.6/lib/byebug/commands/frame.rb", 954]]
18
+ => nil
19
+ ```
20
+
21
+ | Project | GemBench |
22
+ |------------------------ | ----------------- |
23
+ | gem name | gem_bench |
24
+ | license | MIT |
25
+ | expert support | [![Get help on Codementor](https://cdn.codementor.io/badges/get_help_github.svg)](https://www.codementor.io/peterboling?utm_source=github&utm_medium=button&utm_term=peterboling&utm_campaign=github) |
26
+ | download rank | [![Download Rank](https://img.shields.io/gem/rt/gem_bench.svg)](https://rubygems.org/gems/gem_bench) |
27
+ | version | [![Gem Version](https://badge.fury.io/rb/gem_bench.png)](http://badge.fury.io/rb/gem_bench) |
28
+ | dependencies | [![Dependency Status](https://gemnasium.com/pboling/gem_bench.png)](https://gemnasium.com/pboling/gem_bench) |
29
+ | code quality | [![Code Climate](https://codeclimate.com/github/pboling/gem_bench.png)](https://codeclimate.com/github/pboling/gem_bench) |
30
+ | inline documenation | [![Inline docs](http://inch-ci.org/github/pboling/gem_bench.png)](http://inch-ci.org/github/pboling/gem_bench) |
31
+ | continuous integration | [![Build Status](https://secure.travis-ci.org/pboling/gem_bench.png?branch=master)](https://travis-ci.org/pboling/gem_bench) |
32
+ | test coverage | [![Coverage Status](https://coveralls.io/repos/pboling/gem_bench/badge.png)](https://coveralls.io/r/pboling/gem_bench) |
33
+ | homepage | [on Github.com][homepage] |
34
+ | documentation | [on Rdoc.info][documentation] |
35
+ | live chat | [![Join the chat at https://gitter.im/pboling/gem_bench](https://badges.gitter.im/Join%20Chat.svg)](https://gitter.im/pboling/gem_bench?utm_source=badge&utm_medium=badge&utm_campaign=pr-badge&utm_content=badge) |
36
+ | Spread ~♡ⓛⓞⓥⓔ♡~ | [on Coderwall][coderwall] |
37
+
38
+ [semver]: http://semver.org/
39
+ [pvc]: http://docs.rubygems.org/read/chapter/16#page74
40
+ [railsbling]: http://www.railsbling.com
41
+ [peterboling]: http://www.peterboling.com
42
+ [coderwall]: http://coderwall.com/pboling
43
+ [documentation]: http://rdoc.info/github/pboling/gem_bench/frames
44
+ [homepage]: https://github.com/pboling/gem_bench
7
45
 
8
46
  It is a fact of RubyGems that many of them do not need to be loaded by your app at boot time.
9
47
  It is a fact of Bundler that you don't know which ones need to be 'required' while staring at the Gemfile.
10
- It is a fact of Heroku that you only have 60 precious seconds to get your app loaded before ❨╯°□°❩╯︵┻━┻
48
+ It is a fact of Heroku that you only have 60, 75, or 120 ([by special request](https://devcenter.heroku.com/articles/error-codes#h20-app-boot-timeout)) precious seconds to get your app loaded before ❨╯°□°❩╯︵┻━┻
11
49
 
12
50
  This gem helps by telling you which gems don't need to be loaded during boot time.
13
51
 
@@ -43,7 +81,34 @@ And then execute:
43
81
 
44
82
  ## Usage
45
83
 
46
- Works with Ruby >= 1.9.2 due to use of stabby lambdas and the new hash syntax, and probably other stuff.
84
+ Works with Ruby >= 2.0 due to use of named parameters.
85
+
86
+ ### Example!
87
+
88
+ Getting tired of seeing this `irb` warning, perhaps?
89
+
90
+ ```
91
+ $ bundle exec rails console
92
+ Loading staging environment (Rails M.m.p)
93
+ irb: warn: can't alias context from irb_context.
94
+ ```
95
+
96
+ Find out what gems may be causing it by defining `context`!
97
+ ```
98
+ >> require 'gem_bench'
99
+ => true
100
+ >> bad_context_maybe = GemBench.find(look_for_regex: /def context/).starters
101
+ [GemBench] Will search for gems in ["/Users/pboling/.rvm/gems/ruby-2.4.0@foss/gems", "/Users/pboling/.rvm/gems/ruby-2.4.0@global/gems", "/Users/pboling/.rvm/gems/ruby-2.4.0@foss/bundler/gems"]
102
+ [GemBench] Detected 11 loaded gems + 2 loaded gems which GemBench is configured to ignore.
103
+ => [byebug, diff-lcs]
104
+ ```
105
+ Then find the file and line number for the first occurrence of the regex in each:
106
+ ```
107
+ >> bad_context_maybe.stats
108
+ => [[["/Users/pboling/.rvm/gems/ruby-2.4.0@foss/gems/byebug-9.0.6/lib/byebug/command.rb", 777]], [["/Users/pboling/.rvm/gems/ruby-2.4.0@foss/gems/diff-lcs-1.3/lib/diff/lcs/hunk.rb", 5655]]]
109
+ ```
110
+
111
+ ### More Different Example!
47
112
 
48
113
  Fire up an `irb` session or a `rails console` and then:
49
114
 
@@ -97,53 +162,9 @@ See that? Only 3 of the 14 gems rails loads need to be required when your app b
97
162
  However, in order to prevent loading them we would have to make them primary dependencies, listed in the Gemfile, which isn't really the best idea. Moving on...
98
163
  If you run the check against a real app's Gemfile it will find numerous primary dependencies that don't need to be required at app boot. See Advanced Usage :)
99
164
 
100
- In a random directory, in an irb session, where there is no Gemfile in sight it will give a lot more information:
165
+ In a random directory, in an irb session, where there is no Gemfile in sight it will give a lot more information.
101
166
 
102
- irb
103
- >> require 'gem_bench'
104
- => true
105
- >> require 'rails'
106
- => true
107
- >> team = GemBench.check({verbose: true})
108
- [GemBench] Will search for gems in ["/Users/pboling/.rvm/gems/ruby-1.9.3-head@foss/gems", "/Users/pboling/.rvm/gems/ruby-1.9.3-head@global/gems"]
109
- [GemBench] No Gemfile found.
110
- [GemBench] Will show bad ideas. Be Careful.
111
- [GemBench] Detected 14 loaded gems
112
- (excluding the 2 loaded gems which GemBench is configured to ignore)
113
-
114
- [GemBench] Usage: Require another gem in this session to evaluate it.
115
- Example:
116
- require 'rails'
117
- GemBench.check({verbose: true})
118
- [GemBench] You might want to verify that activesupport v3.2.13 really has a Rails::Railtie or Rails::Engine. Check these files:
119
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-head@foss/gems/activesupport-3.2.11/lib/active_support/i18n_railtie.rb", 146]
120
- [GemBench] You might want to verify that actionpack v3.2.13 really has a Rails::Railtie or Rails::Engine. Check these files:
121
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-head@foss/gems/actionpack-3.2.11/lib/action_controller/railtie.rb", 248]
122
- [GemBench] You might want to verify that railties v3.2.13 really has a Rails::Railtie or Rails::Engine. Check these files:
123
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-head@foss/gems/railties-3.2.11/lib/rails/application/configuration.rb", 245]
124
- [GemBench] If you want to check for false positives, the files to check for Railties and Engines are listed above.
125
- [GemBench] 3 out of 14 evaluated gems actually need to be loaded at boot time. They are:
126
- [SUGGESTION] 1) gem 'activesupport', '~> 3.2.13'
127
- [SUGGESTION] 2) gem 'actionpack', '~> 3.2.13'
128
- [SUGGESTION] 3) gem 'railties', '~> 3.2.13'
129
- [GemBench] Evaluated 14 loaded gems and found 11 which may be able to skip boot loading (require: false).
130
- *** => WARNING <= ***: Be careful adding non-primary dependencies to your Gemfile as it is generally a bad idea.
131
- To safely evaluate a Gemfile:
132
- 1. Make sure you are in the root of a project with a Gemfile
133
- 2. Make sure the gem is actually a dependency in the Gemfile
134
- [BE CAREFUL] 1) gem 'i18n', '~> 0.6.1', require: false
135
- [BE CAREFUL] 2) gem 'builder', '~> 3.0.4', require: false
136
- [BE CAREFUL] 3) gem 'activemodel', '~> 3.2.13', require: false
137
- [BE CAREFUL] 4) gem 'rack-cache', '~> 1.2', require: false
138
- [BE CAREFUL] 5) gem 'rack', '~> 1.4.5', require: false
139
- [BE CAREFUL] 6) gem 'rack-test', '~> 0.6.2', require: false
140
- [BE CAREFUL] 7) gem 'journey', '~> 1.0.4', require: false
141
- [BE CAREFUL] 8) gem 'hike', '~> 1.2.1', require: false
142
- [BE CAREFUL] 9) gem 'tilt', '~> 1.3.3', require: false
143
- [BE CAREFUL] 10) gem 'sprockets', '~> 2.2.2', require: false
144
- [BE CAREFUL] 11) gem 'erubis', '~> 2.7.0', require: false
145
-
146
- ## Advanced Usage
167
+ ### Advanced Usage
147
168
 
148
169
  In order to *also* see list gems may *not* be required at boot time you need to:
149
170
 
@@ -156,158 +177,7 @@ So here's a [*fat* Gemfile][bundle-group-pattern] weighing in at 265 gem depende
156
177
  Welcome to RAILS. You are using ruby 1.9.3p392 (2013-02-22 revision 39386) [x86_64-darwin12.2.1]. Have fun ;)
157
178
  Loading development environment (Rails 3.2.13)
158
179
  [1] pry(main)> a = GemBench.check({verbose: true})
159
- [GemBench] Will search for gems in ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems", "/Users/pboling/.rvm/gems/ruby-1.9.3-p392@global/gems", "/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/bundler/gems"]
160
- [GemBench] Will check Gemfile at /Users/pboling/Documents/RubyMineProjects/simple/Gemfile.
161
- [GemBench] Detected 265 loaded gems
162
- (excluding the 2 GemBench is configured to skip)
163
- [GemBench] You might want to verify that activesupport v3.2.13 really has a Rails::Railtie or Rails::Engine. Check these files:
164
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/activesupport-3.2.12/lib/active_support/i18n_railtie.rb", 146]
165
- [GemBench] You might want to verify that sprockets v2.2.2 really has a Rails::Railtie or Rails::Engine. Check these files:
166
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/sprockets-rails-1.0.0/lib/sprockets/rails/railtie.rb", 495]
167
- [GemBench] You might want to verify that actionpack v3.2.13 really has a Rails::Railtie or Rails::Engine. Check these files:
168
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/actionpack-3.2.12/lib/action_controller/railtie.rb", 248]
169
- [GemBench] You might want to verify that actionmailer v3.2.13 really has a Rails::Railtie or Rails::Engine. Check these files:
170
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/actionmailer-3.2.12/lib/action_mailer/railtie.rb", 133]
171
- [GemBench] You might want to verify that activerecord v3.2.13 really has a Rails::Railtie or Rails::Engine. Check these files:
172
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/activerecord-3.2.12/lib/active_record/railtie.rb", 409]
173
- [GemBench] You might want to verify that activerecord-postgres-array v0.0.9 really has a Rails::Railtie or Rails::Engine. Check these files:
174
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/bundler/gems/activerecord-postgres-array-07c5291804a2/lib/activerecord-postgres-array.rb", 55]
175
- [GemBench] You might want to verify that activerecord-postgres-hstore v0.7.6 really has a Rails::Railtie or Rails::Engine. Check these files:
176
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/activerecord-postgres-hstore-0.7.5/lib/activerecord-postgres-hstore/railties.rb", 226]
177
- [GemBench] You might want to verify that activeresource v3.2.13 really has a Rails::Railtie or Rails::Engine. Check these files:
178
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/activeresource-3.2.12/lib/active_resource/railtie.rb", 83]
179
- [GemBench] You might want to verify that railties v3.2.13 really has a Rails::Railtie or Rails::Engine. Check these files:
180
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/railties-3.2.12/lib/rails/application/configuration.rb", 245]
181
- [GemBench] You might want to verify that acts-as-messageable v0.4.8 really has a Rails::Railtie or Rails::Engine. Check these files:
182
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/acts-as-messageable-0.4.8/lib/acts-as-messageable/railtie.rb", 110]
183
- [GemBench] You might want to verify that airbrake v3.1.10 really has a Rails::Railtie or Rails::Engine. Check these files:
184
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/airbrake-3.1.10/lib/airbrake/railtie.rb", 109]
185
- [GemBench] You might want to verify that asset_sync v0.5.4 really has a Rails::Railtie or Rails::Engine. Check these files:
186
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/asset_sync-0.5.4/lib/asset_sync/engine.rb", 34]
187
- [GemBench] You might want to verify that slim v1.3.6 really has a Rails::Railtie or Rails::Engine. Check these files:
188
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/slim-rails-1.1.0/lib/slim-rails.rb", 81]
189
- [GemBench] You might want to verify that sidekiq v2.10.0 really has a Rails::Railtie or Rails::Engine. Check these files:
190
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/sidekiq-2.7.4/lib/sidekiq/rails.rb", 290]
191
- [GemBench] You might want to verify that aws-sdk v1.8.5 really has a Rails::Railtie or Rails::Engine. Check these files:
192
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/aws-sdk-1.8.3.1/lib/aws/rails.rb", 705]
193
- [GemBench] You might want to verify that better_errors v0.8.0 really has a Rails::Railtie or Rails::Engine. Check these files:
194
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/better_errors-0.6.0/lib/better_errors/rails.rb", 51]
195
- [GemBench] You might want to verify that sass v3.2.7 really has a Rails::Railtie or Rails::Engine. Check these files:
196
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/sass-rails-3.2.6/lib/sass/rails/railtie.rb", 68]
197
- [GemBench] You might want to verify that bootstrap-sass v2.3.1.0 really has a Rails::Railtie or Rails::Engine. Check these files:
198
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/bootstrap-sass-2.3.0.1/lib/bootstrap-sass/engine.rb", 53]
199
- [GemBench] You might want to verify that haml v4.0.1 really has a Rails::Railtie or Rails::Engine. Check these files:
200
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/haml-4.0.0/lib/haml/railtie.rb", 232]
201
- [GemBench] You might want to verify that bullet v4.5.0 really has a Rails::Railtie or Rails::Engine. Check these files:
202
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/bullet-4.3.0/lib/bullet.rb", 683]
203
- [GemBench] You might want to verify that parallel v0.6.4 really has a Rails::Railtie or Rails::Engine. Check these files:
204
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/parallel_tests-0.10.0/lib/parallel_tests/railtie.rb", 67]
205
- [GemBench] You might want to verify that cells v3.8.8 really has a Rails::Railtie or Rails::Engine. Check these files:
206
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/cells-3.8.8/lib/cell/rails4_0_strategy.rb", 773]
207
- [GemBench] You might want to verify that coffee-rails v3.2.2 really has a Rails::Railtie or Rails::Engine. Check these files:
208
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/coffee-rails-3.2.2/lib/coffee/rails/engine.rb", 74]
209
- [GemBench] You might want to verify that compass v0.12.2 really has a Rails::Railtie or Rails::Engine. Check these files:
210
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/compass-rails-1.0.3/lib/compass-rails/railties/3_0.rb", 49]
211
- [GemBench] You might want to verify that compass-rails v1.0.3 really has a Rails::Railtie or Rails::Engine. Check these files:
212
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/compass-rails-1.0.3/lib/compass-rails/railties/3_0.rb", 49]
213
- [GemBench] You might want to verify that csv_pirate v5.0.7 really has a Rails::Railtie or Rails::Engine. Check these files:
214
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/csv_pirate-5.0.7/lib/csv_pirate/railtie.rb", 35]
215
- [GemBench] You might want to verify that devise v2.2.3 really has a Rails::Railtie or Rails::Engine. Check these files:
216
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/devise-2.2.3/lib/devise/rails.rb", 101]
217
- [GemBench] You might want to verify that devise_invitable v1.1.3 really has a Rails::Railtie or Rails::Engine. Check these files:
218
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/bundler/gems/devise_invitable-5af50a925e0a/lib/devise_invitable/rails.rb", 42]
219
- [GemBench] You might want to verify that rails v3.2.13 really has a Rails::Railtie or Rails::Engine. Check these files:
220
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/bundler/gems/rails_admin-05a029da6fab/lib/rails_admin/engine.rb", 373]
221
- [GemBench] You might want to verify that dismissible_helpers v0.1.5 really has a Rails::Railtie or Rails::Engine. Check these files:
222
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/dismissible_helpers-0.1.5/lib/dismissible_helpers/engine.rb", 44]
223
- [GemBench] You might want to verify that dotenv v0.6.0 really has a Rails::Railtie or Rails::Engine. Check these files:
224
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/dotenv-0.5.0/lib/dotenv/railtie.rb", 32]
225
- [GemBench] You might want to verify that dry_views v0.0.2 really has a Rails::Railtie or Rails::Engine. Check these files:
226
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/dry_views-0.0.2/lib/dry_views/railtie.rb", 138]
227
- [GemBench] You might want to verify that sass-rails v3.2.6 really has a Rails::Railtie or Rails::Engine. Check these files:
228
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/sass-rails-3.2.6/lib/sass/rails/railtie.rb", 68]
229
- [GemBench] You might want to verify that font-awesome-sass-rails v3.0.2.2 really has a Rails::Railtie or Rails::Engine. Check these files:
230
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/font-awesome-sass-rails-3.0.2.2/lib/font-awesome-sass-rails/engine.rb", 89]
231
- [GemBench] You might want to verify that foundation-icons-sass-rails v2.0.0 really has a Rails::Railtie or Rails::Engine. Check these files:
232
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/foundation-icons-sass-rails-2.0.0/lib/foundation-icons-sass-rails/engine.rb", 95]
233
- [GemBench] You might want to verify that g v1.7.2 really has a Rails::Railtie or Rails::Engine. Check these files:
234
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/gem_bench-0.0.2/lib/gem_bench/team.rb", 2462]
235
- [GemBench] You might want to verify that geocoder v1.1.6 really has a Rails::Railtie or Rails::Engine. Check these files:
236
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/geocoder-1.1.6/lib/geocoder/railtie.rb", 90]
237
- [GemBench] You might want to verify that geokit v1.6.5 really has a Rails::Railtie or Rails::Engine. Check these files:
238
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/bundler/gems/geokit-rails3-9988045e1c4b/lib/geokit-rails3/railtie.rb", 76]
239
- [GemBench] You might want to verify that geokit-rails3 v0.1.5 really has a Rails::Railtie or Rails::Engine. Check these files:
240
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/bundler/gems/geokit-rails3-9988045e1c4b/lib/geokit-rails3/railtie.rb", 76]
241
- [GemBench] You might want to verify that pry v0.9.12 really has a Rails::Railtie or Rails::Engine. Check these files:
242
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/pry-rails-0.2.2/lib/pry-rails/railtie.rb", 53]
243
- [GemBench] You might want to verify that rspec v2.13.0 really has a Rails::Railtie or Rails::Engine. Check these files:
244
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/rspec-rails-2.12.2/lib/rspec-rails.rb", 50]
245
- [GemBench] You might want to verify that spork v1.0.0rc3 really has a Rails::Railtie or Rails::Engine. Check these files:
246
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/spork-rails-3.2.1/lib/spork/app_framework/rails.rb", 1267]
247
- [GemBench] You might want to verify that haml-rails v0.4 really has a Rails::Railtie or Rails::Engine. Check these files:
248
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/haml-rails-0.4/lib/haml-rails.rb", 81]
249
- [GemBench] You might want to verify that handlebars_assets v0.12.0 really has a Rails::Railtie or Rails::Engine. Check these files:
250
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/handlebars_assets-0.12.0/lib/handlebars_assets/engine.rb", 43]
251
- [GemBench] You might want to verify that hirefire-resource v0.0.2 really has a Rails::Railtie or Rails::Engine. Check these files:
252
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/hirefire-resource-0.0.2/lib/hirefire/railtie.rb", 55]
253
- [GemBench] You might want to verify that jquery-rails v2.2.1 really has a Rails::Railtie or Rails::Engine. Check these files:
254
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/jquery-rails-2.1.4/lib/jquery/rails/engine.rb", 50]
255
- [GemBench] You might want to verify that html5-rails v0.0.7 really has a Rails::Railtie or Rails::Engine. Check these files:
256
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/html5-rails-0.0.6/lib/html5/rails/engine.rb", 49]
257
- [GemBench] You might want to verify that jquery-ui-rails v3.0.1 really has a Rails::Railtie or Rails::Engine. Check these files:
258
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/jquery-ui-rails-3.0.1/lib/jquery/ui/rails/engine.rb", 66]
259
- [GemBench] You might want to verify that kaminari v0.14.1 really has a Rails::Railtie or Rails::Engine. Check these files:
260
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/kaminari-0.14.1/lib/kaminari/engine.rb", 44]
261
- [GemBench] You might want to verify that neography v1.0.9 really has a Rails::Railtie or Rails::Engine. Check these files:
262
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/neography-1.0.6/lib/neography/railtie.rb", 52]
263
- [GemBench] You might want to verify that neoid v0.1.2 really has a Rails::Railtie or Rails::Engine. Check these files:
264
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/neoid-0.1.2/lib/neoid/railtie.rb", 59]
265
- [GemBench] You might want to verify that nested_form v0.3.2 really has a Rails::Railtie or Rails::Engine. Check these files:
266
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/nested_form-0.3.1/lib/nested_form/engine.rb", 54]
267
- [GemBench] You might want to verify that newrelic_rpm v3.6.0.78 really has a Rails::Railtie or Rails::Engine. Check these files:
268
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/newrelic_rpm-3.5.5.540.dev/lib/newrelic_rpm.rb", 863]
269
- [GemBench] You might want to verify that parallel_tests v0.10.4 really has a Rails::Railtie or Rails::Engine. Check these files:
270
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/parallel_tests-0.10.0/lib/parallel_tests/railtie.rb", 67]
271
- [GemBench] You might want to verify that pg v0.15.0 really has a Rails::Railtie or Rails::Engine. Check these files:
272
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/pg_power-1.3.0/lib/pg_power/engine.rb", 43]
273
- [GemBench] You might want to verify that rspec-rails v2.13.0 really has a Rails::Railtie or Rails::Engine. Check these files:
274
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/rspec-rails-2.12.2/lib/rspec-rails.rb", 50]
275
- [GemBench] You might want to verify that pg_power v1.3.1 really has a Rails::Railtie or Rails::Engine. Check these files:
276
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/pg_power-1.3.0/lib/pg_power/engine.rb", 43]
277
- [GemBench] You might want to verify that pry-rails v0.2.2 really has a Rails::Railtie or Rails::Engine. Check these files:
278
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/pry-rails-0.2.2/lib/pry-rails/railtie.rb", 53]
279
- [GemBench] You might want to verify that quiet_assets v1.0.2 really has a Rails::Railtie or Rails::Engine. Check these files:
280
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/quiet_assets-1.0.2/lib/quiet_assets.rb", 38]
281
- [GemBench] You might want to verify that remotipart v1.0.5 really has a Rails::Railtie or Rails::Engine. Check these files:
282
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/remotipart-1.0.5/lib/remotipart/rails/engine.rb", 77]
283
- [GemBench] You might want to verify that rails_admin v0.4.6 really has a Rails::Railtie or Rails::Engine. Check these files:
284
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/bundler/gems/rails_admin-05a029da6fab/lib/rails_admin/engine.rb", 373]
285
- [GemBench] You might want to verify that requirejs-rails v0.9.1.1 really has a Rails::Railtie or Rails::Engine. Check these files:
286
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/requirejs-rails-0.9.0/lib/requirejs/rails/engine.rb", 107]
287
- [GemBench] You might want to verify that rolify v3.2.0 really has a Rails::Railtie or Rails::Engine. Check these files:
288
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/rolify-3.2.0/lib/rolify/railtie.rb", 66]
289
- [GemBench] You might want to verify that rspec-cells v0.1.6 really has a Rails::Railtie or Rails::Engine. Check these files:
290
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/bundler/gems/rspec-cells-47232afed355/lib/rspec-cells.rb", 50]
291
- [GemBench] You might want to verify that sanitize_email v1.0.6 really has a Rails::Railtie or Rails::Engine. Check these files:
292
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/sanitize_email-1.0.6/lib/sanitize_email/engine.rb", 144]
293
- [GemBench] You might want to verify that simplecov v0.7.1 really has a Rails::Railtie or Rails::Engine. Check these files:
294
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/simplecov-0.7.1/lib/simplecov/railtie.rb", 37]
295
- [GemBench] You might want to verify that spork-rails v3.2.1 really has a Rails::Railtie or Rails::Engine. Check these files:
296
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/spork-rails-3.2.1/lib/spork/app_framework/rails.rb", 1267]
297
- [GemBench] You might want to verify that sprockets-rails v0.0.1 really has a Rails::Railtie or Rails::Engine. Check these files:
298
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/sprockets-rails-1.0.0/lib/sprockets/rails/railtie.rb", 495]
299
- [GemBench] You might want to verify that stackable_flash v0.0.7 really has a Rails::Railtie or Rails::Engine. Check these files:
300
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/stackable_flash-0.0.7/lib/stackable_flash/railtie.rb", 40]
301
- [GemBench] You might want to verify that state_machine v1.2.0 really has a Rails::Railtie or Rails::Engine. Check these files:
302
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/state_machine-1.1.2/lib/state_machine/initializers/rails.rb", 262]
303
- [GemBench] You might want to verify that teabag v0.4.6 really has a Rails::Railtie or Rails::Engine. Check these files:
304
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/bundler/gems/teabag-0d3fde2505b9/lib/teabag/engine.rb", 33]
305
- [GemBench] You might want to verify that turbo-sprockets-rails3 v0.3.6 really has a Rails::Railtie or Rails::Engine. Check these files:
306
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/turbo-sprockets-rails3-0.3.6/lib/turbo-sprockets/railtie.rb", 179]
307
- [GemBench] You might want to verify that turbolinks v1.1.1 really has a Rails::Railtie or Rails::Engine. Check these files:
308
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/turbolinks-0.6.1/lib/turbolinks.rb", 650]
309
- [GemBench] You might want to verify that zurb-foundation v4.1.1 really has a Rails::Railtie or Rails::Engine. Check these files:
310
- ["/Users/pboling/.rvm/gems/ruby-1.9.3-p392@simple/gems/zurb-foundation-3.2.5/lib/foundation/engine.rb", 35]
180
+ ... # snip # ...
311
181
  [GemBench] If you want to check for false positives, the files to check for Railties and Engines are listed above.
312
182
  [GemBench] 74 out of 265 evaluated gems actually need to be loaded at boot time. They are:
313
183
  [SUGGESTION] 1) gem 'activesupport', '~> 3.2.13', require: false
@@ -444,7 +314,7 @@ When doing these, you will probably encounter errors saying that a library is no
444
314
  add `require "foo"` where the error happens. Keep in mind that if this is in an initializer or environment file,
445
315
  you aren't saving any time when the rails server is booting. However,
446
316
  it does save time when running a rake task that does not invoke the environment (some do, some don't). So, if
447
- you don't think saving this time is worth the minor additinoal code complexity, you can exclude the `require: false`s
317
+ you don't think saving this time is worth the minor additional code complexity, you can exclude the `require: false`s
448
318
  in these cases.
449
319
 
450
320
  After adding your `require: false`s, run gem_bench again. The gem's logic isn't perfect so it sometimes
@@ -457,10 +327,18 @@ How much faster will my app boot loading 45 fewer gems? A bit.
457
327
  ## Future
458
328
 
459
329
  This gem determines which gems need to be loaded at Rails' boot time by looking for Railties and Engines.
460
- A future verison will also look for initializers, because gems which have code that runs (e.g. configuration) in an initializer also need to be loaded at boot time.
330
+ A future version will also look for initializers, because gems which have code that runs (e.g. configuration) in an initializer also need to be loaded at boot time.
331
+
332
+ ## Development
333
+
334
+ 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.
335
+
336
+ 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).
461
337
 
462
338
  ## Contributing
463
339
 
340
+ Bug reports and pull requests are welcome on GitHub at https://github.com/pboling/gem_bench.
341
+
464
342
  If you see: `is feeling very lost right now` then I'd like to know.
465
343
  Create an issue and tell me about it, or fix it yo'sef.
466
344
 
@@ -490,7 +368,7 @@ For example:
490
368
  ## Legal
491
369
 
492
370
  * MIT License
493
- * Copyright (c) 2013 [Peter H. Boling](http://www.railsbling.com), and [Acquaintable](http://acquaintable.com/)
371
+ * Copyright (c) 2013 [Peter H. Boling](http://www.railsbling.com)
494
372
 
495
373
  [semver]: http://semver.org/
496
374
  [pvc]: http://docs.rubygems.org/read/chapter/16#page74
data/Rakefile CHANGED
@@ -1 +1,6 @@
1
1
  require "bundler/gem_tasks"
2
+ require "rspec/core/rake_task"
3
+
4
+ RSpec::Core::RakeTask.new(:spec)
5
+
6
+ task :default => :spec
data/bin/console ADDED
@@ -0,0 +1,14 @@
1
+ #!/usr/bin/env ruby
2
+
3
+ require "bundler/setup"
4
+ require "gem_bench"
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(__FILE__)
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
data/gem_bench.gemspec ADDED
@@ -0,0 +1,35 @@
1
+ # coding: utf-8
2
+ lib = File.expand_path('../lib', __FILE__)
3
+ $LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
4
+ require 'gem_bench/version'
5
+
6
+ Gem::Specification.new do |spec|
7
+ spec.name = "gem_bench"
8
+ spec.version = GemBench::VERSION
9
+ spec.authors = ["Peter Boling"]
10
+ spec.email = ["peter.boling@gmail.com"]
11
+
12
+ spec.summary = %q{Gem: "Put me in coach"
13
+ You: ❨╯°□°❩╯︵┻━┻}
14
+ spec.description = %q{trim down app load times by keeping your worst players on the bench}
15
+ spec.homepage = "http://github.com/acquaintable/gem_bench"
16
+
17
+ spec.licenses = ['MIT']
18
+ spec.platform = Gem::Platform::RUBY
19
+ spec.required_ruby_version = ">= 2.0.0" # because has named parameters with default values
20
+
21
+ spec.files = `git ls-files -z`.split("\x0").reject do |f|
22
+ f.match(%r{^(test|spec|features)/})
23
+ end
24
+ spec.bindir = "exe"
25
+ spec.executables = spec.files.grep(%r{^exe/}) { |f| File.basename(f) }
26
+ spec.require_paths = ["lib"]
27
+ spec.test_files = Dir.glob("{test|spec|features}/**/*")
28
+
29
+ # Yes, it *is* actually a run-time dependency. This gem is sort of a bundler add-on.
30
+ spec.add_runtime_dependency "bundler", "~> 1.14"
31
+ spec.add_development_dependency "rake", "~> 10.5"
32
+ spec.add_development_dependency "rspec", "~> 3.5"
33
+ spec.add_development_dependency "byebug", "~> 9.0"
34
+ spec.add_development_dependency "gem-release", "~> 0.5"
35
+ end
@@ -1,26 +1,37 @@
1
1
  module GemBench
2
2
  class Player
3
-
3
+ # MAJOR.MINOR split on point length == 2
4
+ # MAJOR.MINOR.PATCH split on point length == 3
5
+ # Semver 2.0 Standard is to accept minor and patch updates
6
+ SEMVER_SPLIT_ON_POINT_LENGTH = 2
4
7
  attr_accessor :name, :version, :state, :stats
8
+ attr_reader :file_path_glob, :gemfile_regex, :checked, :exclude_file_pattern
5
9
 
6
10
  def initialize(options = {})
7
11
  @name = options[:name]
8
12
  @version = options[:version]
13
+ @exclude_file_pattern = options[:exclude_file_pattern]
9
14
  @state = nil
10
15
  @stats = []
16
+ @file_path_glob = GemBench::PATH_GLOB.call(@name)
17
+ # Used to find the line of the Gemfile which creates the primary dependency on this gem
18
+ @gemfile_regex = GemBench::DEPENDENCY_REGEX_PROC.call(@name)
19
+ @checked = false
11
20
  end
12
21
 
13
- def path_glob
14
- GemBench::PATH_GLOB.call(self.name)
15
- end
16
-
17
- def set_starter(file_path)
22
+ def set_starter(file_path, line_match: nil)
23
+ return false if file_path =~ exclude_file_pattern
24
+ # Some gems may have zero files to check, as they may be using gem as a
25
+ # delivery system for shell scripts! As such we need to check which
26
+ # gems got checked, and which had nothing to check
27
+ @checked = true
28
+ line_match ||= GemBench::RAILTIE_REGEX
18
29
  scan = begin
19
- if GemBench::DO_NOT_SCAN.include? self.name
30
+ if GemBench::DO_NOT_SCAN.include?(name)
20
31
  false
21
32
  else
22
33
  begin
23
- File.read(file_path).encode('utf-8', :invalid => :replace, :undef => :replace, :replace => '_') =~ GemBench::RAILTIE_REGEX
34
+ File.read(file_path).encode('utf-8', :invalid => :replace, :undef => :replace, :replace => '_') =~ line_match
24
35
  rescue ArgumentError => e
25
36
  if e.message =~ /invalid byte sequence/
26
37
  puts "[GemBench] checking #{file_path} failed due to unparseable file content"
@@ -39,34 +50,60 @@ module GemBench
39
50
  self.state == GemBench::PLAYER_STATES[:starter]
40
51
  end
41
52
 
42
- # Used to find the line of the Gemfile which creates the primary dependency on this gem
43
- def gemfile_regex
44
- GemBench::DEPENDENCY_REGEX.call(self.name)
53
+ def to_s(format = :name)
54
+ case format
55
+ when :name then
56
+ name
57
+ when :v then
58
+ "#{name} v#{version}"
59
+ when :semver
60
+ "gem '#{name}', '~> #{semver}'"
61
+ when :locked
62
+ "gem '#{name}', '#{version}'"
63
+ when :legacy # when depending on legacy gems, you specifically want to not upgrade, except patches.
64
+ "gem '#{name}', '~> #{version}'"
65
+ when :upgrade # when upgrading, and testing gem compatibility you want to try anything newer
66
+ "gem '#{name}', '>= #{version}'"
67
+ end
68
+ end
69
+
70
+ def inspect
71
+ to_s(:name)
45
72
  end
46
73
 
47
- def to_s
48
- "#{self.name} v#{self.version}"
74
+ def semver
75
+ ver = version
76
+ until ver.split(".").length <= SEMVER_SPLIT_ON_POINT_LENGTH do
77
+ ver = ver[0..(ver.rindex(".")-1)]
78
+ end
79
+ ver
49
80
  end
50
81
 
51
82
  def how
52
83
  case self.state
53
- when GemBench::PLAYER_STATES[:starter] then "gem '#{self.name}', '~> #{self.version}'"
54
- when GemBench::PLAYER_STATES[:bench] then "gem '#{self.name}', '~> #{self.version}', require: false"
55
- else "#{self} is feeling very lost right now."
84
+ when GemBench::PLAYER_STATES[:starter] then
85
+ to_s(:semver)
86
+ when GemBench::PLAYER_STATES[:bench] then
87
+ "#{to_s(:semver)}, require: false"
88
+ else
89
+ if checked
90
+ "#{self} is feeling very lost right now."
91
+ else
92
+ "#{self} had no files to evaluate."
93
+ end
56
94
  end
57
95
  end
58
96
 
59
97
  def suggest(num)
60
- "\t[SUGGESTION] #{num}) #{self.how}"
98
+ "\t[SUGGESTION] #{num}) #{how}"
61
99
  end
62
100
 
63
101
  def info(num)
64
- "\t[INFO] #{num}) #{self.how}"
102
+ "\t[INFO] #{num}) #{how}"
65
103
  end
66
104
 
67
105
  def careful(num)
68
- "\t[BE CAREFUL] #{num}) #{self.how}"
106
+ "\t[BE CAREFUL] #{num}) #{how}"
69
107
  end
70
-
71
108
  end
72
109
  end
@@ -0,0 +1,55 @@
1
+ # Scout's job is to figure out where gems are hiding
2
+ #
3
+ module GemBench
4
+ class Scout
5
+ attr_reader :gem_paths, :gemfile_path, :gemfile_lines, :gemfile_trash, :loaded_gems
6
+ def initialize(check_gemfile: nil)
7
+ @check_gemfile = check_gemfile.nil? ? true : check_gemfile
8
+ @gemfile_path = "#{Dir.pwd}/Gemfile"
9
+ gem_lookup_paths_from_bundler
10
+ gem_lines_from_gemfile
11
+ # Gem.loaded_specs are the gems that have been loaded / required.
12
+ @loaded_gems = Gem.loaded_specs.values.map {|x| [x.name, x.version.to_s] }
13
+ end
14
+
15
+ def check_gemfile?
16
+ @check_gemfile
17
+ end
18
+
19
+ private
20
+
21
+ def gem_lookup_paths_from_bundler
22
+ begin
23
+ @gem_paths = [Bundler.rubygems.gem_dir, Bundler.rubygems.gem_path].
24
+ flatten.
25
+ compact.
26
+ uniq.
27
+ map {|x| x.to_s }.
28
+ reject { |p| p.empty? }.
29
+ map {|x| "#{x}/gems" }
30
+ @gem_paths << "#{Bundler.install_path}"
31
+ @gem_paths << "#{Bundler.bundle_path}/gems"
32
+ @gem_paths.uniq!
33
+ rescue Bundler::GemfileNotFound => e
34
+ # Don't fail here, but also don't check the Gemfile.
35
+ @check_gemfile = false
36
+ ensure
37
+ @gem_paths = [] unless @gem_paths.is_a?(Array)
38
+ end
39
+ end
40
+
41
+ def gem_lines_from_gemfile
42
+ if check_gemfile?
43
+ file = File.open(gemfile_path)
44
+ # Get all lines as an array
45
+ all_lines = file.readlines
46
+ # Remove all the commented || blank lines
47
+ @gemfile_trash, @gemfile_lines = all_lines.partition {|x| x =~ GemBench::TRASH_REGEX}
48
+ @gemfile_trash.reject! {|x| x == "\n" } # remove blank lines
49
+ else
50
+ @gemfile_trash = []
51
+ @gemfile_lines = []
52
+ end
53
+ end
54
+ end
55
+ end
@@ -1,74 +1,93 @@
1
+ require "forwardable"
2
+
1
3
  module GemBench
2
4
  class Team
3
-
4
5
  EXCLUDE = [ 'bundler','gem_bench','i18n-airbrake','devise-async','km','vestal_versions','omniauth-facebook',
5
6
  'flag_shih_tzu','pry-remote','koala','simple_form','thumbs_up','memoist','cancan','friendly_id',
6
7
  'faker']
7
8
  # A comment preceding the require: false anywhere on the line should not be considered an active require: false
8
-
9
-
10
- attr_accessor :paths, :all, :excluded, :starters, :benchers, :verbose, :gemfile_lines, :trash_lines, :check_gemfile, :current_gemfile_suggestions, :bad_ideas, :gemfile_path
9
+ extend Forwardable
10
+ def_delegators :@scout, :gem_paths, :gemfile_path, :check_gemfile?, :loaded_gems
11
+ attr_reader :scout, :look_for_regex
12
+ attr_accessor :all, :excluded, :starters, :benchers, :verbose, :gemfile_lines, :trash_lines, :current_gemfile_suggestions, :bad_ideas
11
13
 
12
14
  def initialize(options = {})
13
- possibles = [Bundler.rubygems.gem_dir, Bundler.rubygems.gem_path]
14
- @paths = possibles.flatten.compact.uniq.map {|x| x.to_s }.reject { |p| p.empty? }.map {|x| "#{x}/gems" }
15
- begin
16
- self.paths << "#{Bundler.install_path}"
17
- self.paths << "#{Bundler.bundle_path}/gems"
18
- @check_gemfile = true
19
- @gemfile_path = "#{Dir.pwd}/Gemfile"
20
- rescue Bundler::GemfileNotFound => e
21
- # Don't fail here
22
- ensure
23
- @check_gemfile ||= false
24
- @gemfile_path ||= nil
25
- end
26
- self.paths.uniq!
27
- # Gem.loaded_specs are the gems that have been loaded / required.
28
- # Among these there may be some that did not need to be.
29
- totes = Gem.loaded_specs.values.map {|x| [x.name, x.version.to_s] }
30
- @excluded, @all = totes.partition {|x| EXCLUDE.include?(x[0]) }
31
- exclusions = "\t(excluding the #{self.excluded.length} loaded gems which GemBench is configured to ignore)\n" if @excluded.length > 0
15
+ @look_for_regex = options[:look_for_regex]
16
+ # find: Find gems containing specific strings in code
17
+ # bench: Find gems that can probably be benched (require: false) in the Gemfile
18
+ @check_type = @look_for_regex ? :find : :bench
19
+ @benching = @check_type == :bench
20
+ @scout = GemBench::Scout.new(check_gemfile: options[:check_gemfile] || benching?)
21
+ @exclude_file_pattern_regex_proc = options[:exclude_file_pattern_regex_proc].respond_to?(:call) ? options[:exclude_file_pattern_regex_proc] : GemBench::EXCLUDE_FILE_PATTERN_REGEX_PROC
22
+ # Among the loaded gems there may be some that did not need to be.
23
+ @excluded, @all = @scout.loaded_gems.partition {|x| EXCLUDE.include?(x[0]) }
24
+ exclusions = " + #{self.excluded.length} loaded gems which GemBench is configured to ignore.\n" if @excluded.length > 0
32
25
  @starters = []
33
26
  @benchers = []
34
27
  @current_gemfile_suggestions = []
35
28
  @verbose = options[:verbose]
36
29
  self.check_all
37
- @bad_ideas = options[:bad_ideas] ? true : self.check_gemfile ? false : options[:bad_ideas] == false ? false : true
38
- puts "[GemBench] Will search for gems in #{self.paths.inspect}\n#{self.check_gemfile ? "[GemBench] Will check Gemfile at #{self.gemfile_path}.\n" : "[GemBench] No Gemfile found.\n"}#{self.bad_ideas ? "[GemBench] Will show bad ideas. Be Careful.\n" : ''}[GemBench] Detected #{self.all.length} loaded gems\n#{exclusions}"
39
- self.compare_gemfile if self.check_gemfile
30
+ @bad_ideas = if benching?
31
+ options[:bad_ideas] ? true : check_gemfile? ? false : options[:bad_ideas] == false ? false : true
32
+ else
33
+ false
34
+ end
35
+ puts "[GemBench] Will search for gems in #{gem_paths.inspect}\n#{benching? ? @scout.check_gemfile? ? "[GemBench] Will check Gemfile at #{gemfile_path}.\n" : "[GemBench] No Gemfile found.\n" : ""}#{self.bad_ideas ? "[GemBench] Will show bad ideas. Be Careful.\n" : ''}[GemBench] Detected #{self.all.length} loaded gems#{exclusions}"
36
+ self.compare_gemfile if benching? && @scout.check_gemfile?
40
37
  self.print if self.verbose
41
38
  end
42
39
 
40
+ def list_starters(format: :name)
41
+ starters.map {|starter| starter.to_s(format)}
42
+ end
43
+
43
44
  def print
44
45
  string = ''
45
46
  if self.all.empty?
46
47
  string << nothing
47
48
  elsif self.starters.empty?
48
- string << "[GemBench] Found no gems that need to load at boot time.\n"
49
+ string << if benching?
50
+ "[GemBench] Found no gems that need to load at boot time.\n"
51
+ else
52
+ "[GemBench] Found no gems containing #{look_for_regex} in Ruby code.\n"
53
+ end
49
54
  else
50
55
  if self.starters.length > 0
51
- string << "\n#{GemBench::USAGE}" unless self.check_gemfile
52
- string << "[GemBench] We found a Rails::Railtie or Rails::Engine in the following files. However, it is possible that there are false positives, so you may want to verify that this is the case.\n\n"
56
+ string << "\n#{GemBench::USAGE}" unless check_gemfile?
57
+ string << if benching?
58
+ "[GemBench] We found a Rails::Railtie or Rails::Engine in the following files. However, it is possible that there are false positives, so you may want to verify that this is the case.\n\n"
59
+ else
60
+ "[GemBench] We found #{look_for_regex} in the following files.\n\n"
61
+ end
53
62
  self.starters.each do |starter|
54
63
  string << "\t#{starter}:\n"
55
64
  starter.stats.each do |stat|
56
65
  string << "\t\t#{stat[0]}:#{stat[1]}\n"
57
66
  end
58
67
  end
59
- string << "[GemBench] If you want to check for false positives, the files to check for Railties and Engines are listed above.\n"
60
- string << "[GemBench] #{self.starters.length} out of #{self.all.length} evaluated gems actually need to be loaded at boot time. They are:\n"
68
+ string << "[GemBench] If you want to check for false positives, the files to check for Railties and Engines are listed above.\n" if benching?
69
+ string << if benching?
70
+ "[GemBench] #{self.starters.length} out of #{self.all.length} evaluated gems actually need to be loaded at boot time. They are:\n"
71
+ else
72
+ "[GemBench] #{self.starters.length} out of #{self.all.length} evaluated gems contain #{look_for_regex}. They are:\n"
73
+ end
61
74
  self.starters.each_with_index do |starter, index|
62
75
  string << "#{starter.info(index + 1)}\n"
63
76
  end
77
+ if extra_verbose? && !benching? && self.benchers.length > 0
78
+ string << "[GemBench] #{self.benchers.length} out of #{self.all.length} evaluated gems did not contain #{look_for_regex}. They are:\n"
79
+ self.benchers.each_with_index do |bencher, index|
80
+ string << "#{bencher.info(index + 1)}\n"
81
+ end
82
+ end
64
83
  else
65
- string << "[GemBench] Congrats! No gems to load at boot.\n"
66
- string << "\n#{GemBench::USAGE}" unless self.check_gemfile
84
+ string << "[GemBench] Congrats! All gems appear clean.\n"
85
+ string << "\n#{GemBench::USAGE}" unless check_gemfile?
67
86
  end
68
87
  end
69
- if self.check_gemfile
88
+ if check_gemfile? && benching?
70
89
  if self.current_gemfile_suggestions.length > 0
71
- string << "[GemBench] Evaluated #{self.all.length} gems and Gemfile at #{self.gemfile_path}.\n[GemBench] Here are #{self.current_gemfile_suggestions.length} suggestions for improvement:\n"
90
+ string << "[GemBench] Evaluated #{self.all.length} gems and Gemfile at #{gemfile_path}.\n[GemBench] Here are #{self.current_gemfile_suggestions.length} suggestions for improvement:\n"
72
91
  self.current_gemfile_suggestions.each_with_index do |player, index|
73
92
  string << "#{player.suggest(index + 1)}\n"
74
93
  end
@@ -77,7 +96,7 @@ module GemBench
77
96
  end
78
97
  end
79
98
 
80
- if self.bad_ideas
99
+ if benching? && self.bad_ideas
81
100
  # Only bad ideas if you are evaluating an actual Gemfile. If just evaluating loaded gems, then info is fine.
82
101
  string << self.prepare_bad_ideas
83
102
  end
@@ -86,7 +105,7 @@ module GemBench
86
105
  end
87
106
 
88
107
  def strike_out
89
- self.check_gemfile ?
108
+ check_gemfile? ?
90
109
  "[GemBench] Evaluated #{self.all.length} gems against your Gemfile but found no primary dependencies which can safely skip require on boot (require: false).\n" :
91
110
  "[GemBench] Evaluated #{self.all.length} gems but found none which can safely skip require on boot (require: false).\n"
92
111
  end
@@ -98,7 +117,7 @@ module GemBench
98
117
  def prepare_bad_ideas
99
118
  string = ''
100
119
  if self.benchers.length > 0
101
- gemfile_instruction = self.check_gemfile ? '' : "To safely evaluate a Gemfile:\n\t1. Make sure you are in the root of a project with a Gemfile\n\t2. Make sure the gem is actually a dependency in the Gemfile\n"
120
+ gemfile_instruction = check_gemfile? ? '' : "To safely evaluate a Gemfile:\n\t1. Make sure you are in the root of a project with a Gemfile\n\t2. Make sure the gem is actually a dependency in the Gemfile\n"
102
121
  string << "[GemBench] Evaluated #{self.all.length} loaded gems and found #{self.benchers.length} which may be able to skip boot loading (require: false).\n*** => WARNING <= ***: Be careful adding non-primary dependencies to your Gemfile as it is generally a bad idea.\n#{gemfile_instruction}"
103
122
  self.benchers.each_with_index do |player, index|
104
123
  string << "#{player.careful(index + 1)}\n"
@@ -110,13 +129,8 @@ module GemBench
110
129
  end
111
130
 
112
131
  def compare_gemfile
113
- f = File.open(self.gemfile_path)
114
- # Get all lines as an array
115
- all_lines = f.readlines
116
- # Remove all the commented || blank lines
117
- self.trash_lines, self.gemfile_lines = all_lines.partition {|x| x =~ GemBench::TRASH_REGEX}
118
- self.benchers.each_with_index do |player, index|
119
- self.gemfile_lines.each do |line|
132
+ self.benchers.each do |player|
133
+ scout.gemfile_lines.each do |line|
120
134
  found = (line =~ player.gemfile_regex)
121
135
  if found
122
136
  # remove the found line from the array, because no sane person has more than one gem dependency per line... right?
@@ -131,19 +145,20 @@ module GemBench
131
145
 
132
146
  def check_all
133
147
  self.all.each do |player_data|
134
- player = GemBench::Player.new({name: player_data[0], version: player_data[1]})
148
+ exclude_file_pattern = @exclude_file_pattern_regex_proc.call(player_data[0])
149
+ player = GemBench::Player.new({name: player_data[0], version: player_data[1], exclude_file_pattern: exclude_file_pattern})
135
150
  self.check(player)
136
151
  self.add_to_roster(player)
137
152
  end
138
153
  end
139
154
 
140
155
  def check(player)
141
- self.paths.each do |path|
142
- glob_path = "#{path}/#{player.path_glob}"
156
+ gem_paths.each do |path|
157
+ glob_path = "#{path}/#{player.file_path_glob}"
143
158
  file_paths = Dir.glob("#{glob_path}")
144
- puts "[GemBench] checking #{player} at #{glob_path} (#{file_paths.length} files)" if self.verbose == 'extra'
159
+ puts "[GemBench] checking #{player} at #{glob_path} (#{file_paths.length} files)" if extra_verbose?
145
160
  file_paths.each do |file_path|
146
- player.set_starter(file_path)
161
+ player.set_starter(file_path, line_match: look_for_regex)
147
162
  return if player.starter?
148
163
  end
149
164
  end
@@ -157,5 +172,14 @@ module GemBench
157
172
  end
158
173
  end
159
174
 
175
+ private
176
+
177
+ def extra_verbose?
178
+ self.verbose == "extra"
179
+ end
180
+
181
+ def benching?
182
+ @benching
183
+ end
160
184
  end
161
185
  end
@@ -1,3 +1,3 @@
1
1
  module GemBench
2
- VERSION = "0.0.8"
2
+ VERSION = "1.0.0"
3
3
  end
data/lib/gem_bench.rb CHANGED
@@ -1,27 +1,31 @@
1
- module GemBench
1
+ require "gem_bench/version"
2
+ require "bundler" # This gem utilizes bundler as a tool.
3
+ require "gem_bench/scout"
4
+ require "gem_bench/player"
5
+ require "gem_bench/team"
2
6
 
7
+ module GemBench
3
8
  USAGE = "[GemBench] Usage: Require another gem in this session to evaluate it.\n\tExample:\n\t\trequire 'rails'\n\t\tGemBench.check({verbose: true})\n"
4
9
  RAILTIE_REGEX = /Rails::Engine|Rails::Railtie/
5
10
  TRASH_REGEX = /^(\s*)([#]+.*)?$/
6
11
  REQUIRE_FALSE_REGEX = /^[^#]+require(([:]\s*)|(\s*=>\s*))false.*/
7
- DEPENDENCY_REGEX = ->(name) { /^\s*[^#]*\s*gem\s+['"]{1}#{name}['"]{1}/ }
12
+ DEPENDENCY_REGEX_PROC = ->(name) { /^\s*[^#]*\s*gem\s+['"]{1}#{name}['"]{1}/ }
8
13
  PATH_GLOB = ->(name) { "#{name}*/lib/**/*.rb" }
14
+ EXCLUDE_FILE_PATTERN_REGEX_PROC = ->(name) { /#{name}\/test|features|spec/ }
9
15
  DO_NOT_SCAN = []
10
16
  PLAYER_STATES = {
11
17
  starter: :starter,
12
18
  bench: :bench
13
19
  }
14
20
 
15
- require 'bundler' # This gem utilizes bundler as a tool.
16
- require 'gem_bench/version'
17
- require 'gem_bench/team'
18
- require 'gem_bench/player'
19
-
20
21
  class << self
21
22
  attr_accessor :roster
22
- def check(verbose = false)
23
+ def check(verbose: false)
23
24
  @roster = GemBench::Team.new({verbose: verbose})
24
25
  end
25
- end
26
26
 
27
+ def find(look_for_regex: GemBench::RAILTIE_REGEX, exclude_file_pattern_regex_proc: GemBench::EXCLUDE_FILE_PATTERN_REGEX_PROC, verbose: false)
28
+ @roster = GemBench::Team.new({look_for_regex: look_for_regex, exclude_file_pattern_regex_proc: exclude_file_pattern_regex_proc, verbose: verbose})
29
+ end
30
+ end
27
31
  end
metadata CHANGED
@@ -1,43 +1,85 @@
1
1
  --- !ruby/object:Gem::Specification
2
2
  name: gem_bench
3
3
  version: !ruby/object:Gem::Version
4
- version: 0.0.8
4
+ version: 1.0.0
5
5
  platform: ruby
6
6
  authors:
7
7
  - Peter Boling
8
8
  autorequire:
9
- bindir: bin
9
+ bindir: exe
10
10
  cert_chain: []
11
- date: 2014-01-16 00:00:00.000000000 Z
11
+ date: 2017-02-26 00:00:00.000000000 Z
12
12
  dependencies:
13
13
  - !ruby/object:Gem::Dependency
14
14
  name: bundler
15
15
  requirement: !ruby/object:Gem::Requirement
16
16
  requirements:
17
- - - ! '>'
17
+ - - "~>"
18
18
  - !ruby/object:Gem::Version
19
- version: '1.2'
19
+ version: '1.14'
20
20
  type: :runtime
21
21
  prerelease: false
22
22
  version_requirements: !ruby/object:Gem::Requirement
23
23
  requirements:
24
- - - ! '>'
24
+ - - "~>"
25
25
  - !ruby/object:Gem::Version
26
- version: '1.2'
26
+ version: '1.14'
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.5'
34
+ type: :development
35
+ prerelease: false
36
+ version_requirements: !ruby/object:Gem::Requirement
37
+ requirements:
38
+ - - "~>"
39
+ - !ruby/object:Gem::Version
40
+ version: '10.5'
41
+ - !ruby/object:Gem::Dependency
42
+ name: rspec
43
+ requirement: !ruby/object:Gem::Requirement
44
+ requirements:
45
+ - - "~>"
46
+ - !ruby/object:Gem::Version
47
+ version: '3.5'
48
+ type: :development
49
+ prerelease: false
50
+ version_requirements: !ruby/object:Gem::Requirement
51
+ requirements:
52
+ - - "~>"
53
+ - !ruby/object:Gem::Version
54
+ version: '3.5'
55
+ - !ruby/object:Gem::Dependency
56
+ name: byebug
57
+ requirement: !ruby/object:Gem::Requirement
58
+ requirements:
59
+ - - "~>"
60
+ - !ruby/object:Gem::Version
61
+ version: '9.0'
62
+ type: :development
63
+ prerelease: false
64
+ version_requirements: !ruby/object:Gem::Requirement
65
+ requirements:
66
+ - - "~>"
67
+ - !ruby/object:Gem::Version
68
+ version: '9.0'
27
69
  - !ruby/object:Gem::Dependency
28
70
  name: gem-release
29
71
  requirement: !ruby/object:Gem::Requirement
30
72
  requirements:
31
- - - ! '>='
73
+ - - "~>"
32
74
  - !ruby/object:Gem::Version
33
- version: '0'
75
+ version: '0.5'
34
76
  type: :development
35
77
  prerelease: false
36
78
  version_requirements: !ruby/object:Gem::Requirement
37
79
  requirements:
38
- - - ! '>='
80
+ - - "~>"
39
81
  - !ruby/object:Gem::Version
40
- version: '0'
82
+ version: '0.5'
41
83
  description: trim down app load times by keeping your worst players on the bench
42
84
  email:
43
85
  - peter.boling@gmail.com
@@ -45,14 +87,23 @@ executables: []
45
87
  extensions: []
46
88
  extra_rdoc_files: []
47
89
  files:
48
- - lib/gem_bench/player.rb
49
- - lib/gem_bench/team.rb
50
- - lib/gem_bench/version.rb
51
- - lib/gem_bench.rb
90
+ - ".byebug_history"
91
+ - ".gitignore"
92
+ - ".rspec"
93
+ - ".travis.yml"
94
+ - CHANGELOG
95
+ - Gemfile
52
96
  - LICENSE.txt
53
97
  - README.md
54
- - CHANGELOG
55
98
  - Rakefile
99
+ - bin/console
100
+ - bin/setup
101
+ - gem_bench.gemspec
102
+ - lib/gem_bench.rb
103
+ - lib/gem_bench/player.rb
104
+ - lib/gem_bench/scout.rb
105
+ - lib/gem_bench/team.rb
106
+ - lib/gem_bench/version.rb
56
107
  homepage: http://github.com/acquaintable/gem_bench
57
108
  licenses:
58
109
  - MIT
@@ -63,18 +114,18 @@ require_paths:
63
114
  - lib
64
115
  required_ruby_version: !ruby/object:Gem::Requirement
65
116
  requirements:
66
- - - ! '>='
117
+ - - ">="
67
118
  - !ruby/object:Gem::Version
68
- version: '0'
119
+ version: 2.0.0
69
120
  required_rubygems_version: !ruby/object:Gem::Requirement
70
121
  requirements:
71
- - - ! '>='
122
+ - - ">="
72
123
  - !ruby/object:Gem::Version
73
124
  version: '0'
74
125
  requirements: []
75
126
  rubyforge_project:
76
- rubygems_version: 2.1.11
127
+ rubygems_version: 2.6.8
77
128
  signing_key:
78
129
  specification_version: 4
79
- summary: ! 'Gem: "Put me in coach" You: ❨╯°□°❩╯︵┻━┻'
130
+ summary: 'Gem: "Put me in coach" You: ❨╯°□°❩╯︵┻━┻'
80
131
  test_files: []