resquire 1.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +7 -0
- data/.gitignore +9 -0
- data/.rspec +2 -0
- data/.travis.yml +5 -0
- data/CODE_OF_CONDUCT.md +74 -0
- data/Gemfile +4 -0
- data/LICENSE.txt +21 -0
- data/README.md +64 -0
- data/Rakefile +6 -0
- data/bin/console +14 -0
- data/bin/resquire +71 -0
- data/bin/setup +8 -0
- data/examples/analyzer.rb +23 -0
- data/lib/resquire.rb +40 -0
- data/lib/resquire/analyzer.rb +180 -0
- data/lib/resquire/banner.rb +5 -0
- data/lib/resquire/errors.rb +17 -0
- data/lib/resquire/version.rb +3 -0
- data/lib/template.rb +14 -0
- data/resquire.gemspec +29 -0
- metadata +152 -0
checksums.yaml
ADDED
@@ -0,0 +1,7 @@
|
|
1
|
+
---
|
2
|
+
SHA1:
|
3
|
+
metadata.gz: b06d01256fbedba7ff6783835677ce94e7494f89
|
4
|
+
data.tar.gz: e531f8b80e1e99b69e32657b5cd94400e1e5646a
|
5
|
+
SHA512:
|
6
|
+
metadata.gz: 315caa67424e7419263cb171c94554c5cd9777b0b186144af1d40917ab073a940509be41d06427aa088bc700cbe3cb10b3822b4a6b59f3bf7a4170b56939a21f
|
7
|
+
data.tar.gz: d148ef9bdfbd34480da2b0b2334a57a4b76761d83dfd87e623f43f4c751f38512729d3d5e9834aab20e5aedb037cff80176dfb96f0664c6ef08397d5572b351c
|
data/.gitignore
ADDED
data/.rspec
ADDED
data/.travis.yml
ADDED
data/CODE_OF_CONDUCT.md
ADDED
@@ -0,0 +1,74 @@
|
|
1
|
+
# Contributor Covenant Code of Conduct
|
2
|
+
|
3
|
+
## Our Pledge
|
4
|
+
|
5
|
+
In the interest of fostering an open and welcoming environment, we as
|
6
|
+
contributors and maintainers pledge to making participation in our project and
|
7
|
+
our community a harassment-free experience for everyone, regardless of age, body
|
8
|
+
size, disability, ethnicity, gender identity and expression, level of experience,
|
9
|
+
nationality, personal appearance, race, religion, or sexual identity and
|
10
|
+
orientation.
|
11
|
+
|
12
|
+
## Our Standards
|
13
|
+
|
14
|
+
Examples of behavior that contributes to creating a positive environment
|
15
|
+
include:
|
16
|
+
|
17
|
+
* Using welcoming and inclusive language
|
18
|
+
* Being respectful of differing viewpoints and experiences
|
19
|
+
* Gracefully accepting constructive criticism
|
20
|
+
* Focusing on what is best for the community
|
21
|
+
* Showing empathy towards other community members
|
22
|
+
|
23
|
+
Examples of unacceptable behavior by participants include:
|
24
|
+
|
25
|
+
* The use of sexualized language or imagery and unwelcome sexual attention or
|
26
|
+
advances
|
27
|
+
* Trolling, insulting/derogatory comments, and personal or political attacks
|
28
|
+
* Public or private harassment
|
29
|
+
* Publishing others' private information, such as a physical or electronic
|
30
|
+
address, without explicit permission
|
31
|
+
* Other conduct which could reasonably be considered inappropriate in a
|
32
|
+
professional setting
|
33
|
+
|
34
|
+
## Our Responsibilities
|
35
|
+
|
36
|
+
Project maintainers are responsible for clarifying the standards of acceptable
|
37
|
+
behavior and are expected to take appropriate and fair corrective action in
|
38
|
+
response to any instances of unacceptable behavior.
|
39
|
+
|
40
|
+
Project maintainers have the right and responsibility to remove, edit, or
|
41
|
+
reject comments, commits, code, wiki edits, issues, and other contributions
|
42
|
+
that are not aligned to this Code of Conduct, or to ban temporarily or
|
43
|
+
permanently any contributor for other behaviors that they deem inappropriate,
|
44
|
+
threatening, offensive, or harmful.
|
45
|
+
|
46
|
+
## Scope
|
47
|
+
|
48
|
+
This Code of Conduct applies both within project spaces and in public spaces
|
49
|
+
when an individual is representing the project or its community. Examples of
|
50
|
+
representing a project or community include using an official project e-mail
|
51
|
+
address, posting via an official social media account, or acting as an appointed
|
52
|
+
representative at an online or offline event. Representation of a project may be
|
53
|
+
further defined and clarified by project maintainers.
|
54
|
+
|
55
|
+
## Enforcement
|
56
|
+
|
57
|
+
Instances of abusive, harassing, or otherwise unacceptable behavior may be
|
58
|
+
reported by contacting the project team at kgruber1@emich.edu. All
|
59
|
+
complaints will be reviewed and investigated and will result in a response that
|
60
|
+
is deemed necessary and appropriate to the circumstances. The project team is
|
61
|
+
obligated to maintain confidentiality with regard to the reporter of an incident.
|
62
|
+
Further details of specific enforcement policies may be posted separately.
|
63
|
+
|
64
|
+
Project maintainers who do not follow or enforce the Code of Conduct in good
|
65
|
+
faith may face temporary or permanent repercussions as determined by other
|
66
|
+
members of the project's leadership.
|
67
|
+
|
68
|
+
## Attribution
|
69
|
+
|
70
|
+
This Code of Conduct is adapted from the [Contributor Covenant][homepage], version 1.4,
|
71
|
+
available at [http://contributor-covenant.org/version/1/4][version]
|
72
|
+
|
73
|
+
[homepage]: http://contributor-covenant.org
|
74
|
+
[version]: http://contributor-covenant.org/version/1/4/
|
data/Gemfile
ADDED
data/LICENSE.txt
ADDED
@@ -0,0 +1,21 @@
|
|
1
|
+
The MIT License (MIT)
|
2
|
+
|
3
|
+
Copyright (c) 2016 Kent Gruber
|
4
|
+
|
5
|
+
Permission is hereby granted, free of charge, to any person obtaining a copy
|
6
|
+
of this software and associated documentation files (the "Software"), to deal
|
7
|
+
in the Software without restriction, including without limitation the rights
|
8
|
+
to use, copy, modify, merge, publish, distribute, sublicense, and/or sell
|
9
|
+
copies of the Software, and to permit persons to whom the Software is
|
10
|
+
furnished to do so, subject to the following conditions:
|
11
|
+
|
12
|
+
The above copyright notice and this permission notice shall be included in
|
13
|
+
all copies or substantial portions of the Software.
|
14
|
+
|
15
|
+
THE SOFTWARE IS PROVIDED "AS IS", WITHOUT WARRANTY OF ANY KIND, EXPRESS OR
|
16
|
+
IMPLIED, INCLUDING BUT NOT LIMITED TO THE WARRANTIES OF MERCHANTABILITY,
|
17
|
+
FITNESS FOR A PARTICULAR PURPOSE AND NONINFRINGEMENT. IN NO EVENT SHALL THE
|
18
|
+
AUTHORS OR COPYRIGHT HOLDERS BE LIABLE FOR ANY CLAIM, DAMAGES OR OTHER
|
19
|
+
LIABILITY, WHETHER IN AN ACTION OF CONTRACT, TORT OR OTHERWISE, ARISING FROM,
|
20
|
+
OUT OF OR IN CONNECTION WITH THE SOFTWARE OR THE USE OR OTHER DEALINGS IN
|
21
|
+
THE SOFTWARE.
|
data/README.md
ADDED
@@ -0,0 +1,64 @@
|
|
1
|
+
# Resquire
|
2
|
+
|
3
|
+
Reduce your redundant gem depenencies with resquire, which figures out which gems are redundant so you can require less gems for your ruby projects while still retaining the same functionality! By reducing redundant gems, you can make your application faster!
|
4
|
+
|
5
|
+
![David I of Scotland knighting a squire](https://upload.wikimedia.org/wikipedia/commons/3/3f/DavidI%26squire.jpg)
|
6
|
+
|
7
|
+
## Installation
|
8
|
+
|
9
|
+
While this gem is still in development, but when it's all done you'll be able to install it like so:
|
10
|
+
|
11
|
+
$ gem install resquire
|
12
|
+
|
13
|
+
## Usage
|
14
|
+
|
15
|
+
```ruby
|
16
|
+
require "resquire"
|
17
|
+
|
18
|
+
# you can add gems when you create a new analyzer, as an array
|
19
|
+
analyzer = Resquire::Analyzer.new(:gems => ['colorize', 'packetfu', 'lolize'])
|
20
|
+
|
21
|
+
# you can also add gems individually
|
22
|
+
analyzer.add_gem('pcaprub')
|
23
|
+
# => true
|
24
|
+
|
25
|
+
# or as an array
|
26
|
+
analyzer.add_gems(['ipaddr', 'socket', 'thread'])
|
27
|
+
# => true
|
28
|
+
|
29
|
+
# we can check which gems the analyzer has to work with
|
30
|
+
analyzer.gems
|
31
|
+
# => ["colorize", "packetfu", "lolize", "pcaprub", "ipaddr", "socket", "thread"]
|
32
|
+
|
33
|
+
# quickly check ammount of permutations ( to see wtf we're about to get outselves into )
|
34
|
+
# no, srsly, like, you can easily have 20 gems; and that's 2,432,902,008,176,640,000 permutations dog, fo real
|
35
|
+
# you can try splitting them up into smaller batches of roughly ~13
|
36
|
+
analyzer.permutations
|
37
|
+
# => 5040
|
38
|
+
|
39
|
+
# you can get an array of the redundant gems
|
40
|
+
analyzer.redundant_gems
|
41
|
+
# => ["pcaprub", "ipaddr", "socket", "thread"]
|
42
|
+
|
43
|
+
# you can choose not to shuffle the permutated array, may be better for larger gem groups
|
44
|
+
# since we're not pre-generating the permutations -- we're simply looping through the
|
45
|
+
# possibilities via an enumerator.
|
46
|
+
# true by default, since I find it to be generally nicer
|
47
|
+
analyzer.redundant_gems(:shuffle => false)
|
48
|
+
# => ["pcaprub", "ipaddr", "socket", "thread"]
|
49
|
+
|
50
|
+
# you can also choose to to display a small progresss indicator or not
|
51
|
+
# true by default, since I find it to be generally faster
|
52
|
+
analyzer.redundant_gems(:progress_bar => false)
|
53
|
+
# => ["pcaprub", "ipaddr", "socket", "thread"]
|
54
|
+
|
55
|
+
# or the new optimized gem listing as an array with the redundancies
|
56
|
+
# these would be the gems you'd want to require in your application now
|
57
|
+
analyzer.optimized_gems
|
58
|
+
# => ["colorize", "lolize", "packetfu"]
|
59
|
+
```
|
60
|
+
|
61
|
+
## License
|
62
|
+
|
63
|
+
The gem is available as open source under the terms of the [MIT License](http://opensource.org/licenses/MIT).
|
64
|
+
|
data/Rakefile
ADDED
data/bin/console
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
#!/usr/bin/env ruby
|
2
|
+
|
3
|
+
require "bundler/setup"
|
4
|
+
require "resquire"
|
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/resquire
ADDED
@@ -0,0 +1,71 @@
|
|
1
|
+
require "resquire"
|
2
|
+
require "colorize"
|
3
|
+
require "trollop"
|
4
|
+
|
5
|
+
# default help menu
|
6
|
+
foo = ARGV[0] || ARGV[0] = '-h'
|
7
|
+
|
8
|
+
opts = Trollop::options do
|
9
|
+
banner Resquire::BANNER.bold
|
10
|
+
opt :gems, 'gems to find redudancies from', :type => :strings, :required => true
|
11
|
+
opt :banner, 'use resquire banner or not', :default => true
|
12
|
+
opt :shuffle, 'use the shuffle algorithm', :default => true
|
13
|
+
opt :progress, 'use progress indicator, useful for large gem groups', :default => false
|
14
|
+
opt :Permutations, 'show permutations and exit from given gems', :default => false
|
15
|
+
opt :iterate, 'use the iterate algorithm', :default => false
|
16
|
+
opt :color, 'color output or not', :default => true
|
17
|
+
opt :diff, 'show diff of optimized / redundant gems', :default => true
|
18
|
+
opt :rainbows, 'rainbow option, because we need it', :default => false
|
19
|
+
end
|
20
|
+
|
21
|
+
# rainbow hook
|
22
|
+
require 'lolize/auto' if opts[:rainbows]
|
23
|
+
|
24
|
+
analyzer = Resquire::Analyzer.new(:gems => opts[:gems])
|
25
|
+
|
26
|
+
if opts[:Permutations]
|
27
|
+
if [:color]
|
28
|
+
puts "Permutations: ".bold + "#{analyzer.permutations}"
|
29
|
+
else
|
30
|
+
puts "Permutations: #{analyzer.permutations}"
|
31
|
+
end
|
32
|
+
exit 0
|
33
|
+
end
|
34
|
+
|
35
|
+
redundant = analyzer.redundant_gems(:shuffle => opts[:shuffle], :iterate => opts[:iterate],:progress_bar => opts[:progress])
|
36
|
+
|
37
|
+
optimized = analyzer.optimized_gems
|
38
|
+
|
39
|
+
if redundant == false
|
40
|
+
if opts[:color]
|
41
|
+
puts "No redundant gems found!".red
|
42
|
+
else
|
43
|
+
puts "No redundant gems found!"
|
44
|
+
end
|
45
|
+
exit 1
|
46
|
+
end
|
47
|
+
|
48
|
+
if opts[:diff]
|
49
|
+
if opts[:color]
|
50
|
+
puts 'Redundant:'.bold
|
51
|
+
redundant.each { |gem| puts gem.red }
|
52
|
+
puts '----------------------------'
|
53
|
+
puts 'Optimized:'.bold
|
54
|
+
optimized.each { |gem| puts gem.green }
|
55
|
+
else
|
56
|
+
puts 'Redundant:'
|
57
|
+
redundant.each { |gem| puts gem }
|
58
|
+
puts '----------------------------'
|
59
|
+
puts 'Optimizied:'
|
60
|
+
optimized.each { |gem| puts gem }
|
61
|
+
end
|
62
|
+
else
|
63
|
+
if opts[:color]
|
64
|
+
optimized.each { |gem| puts gem.green }
|
65
|
+
else
|
66
|
+
optimized.each { |gem| puts gem }
|
67
|
+
end
|
68
|
+
end
|
69
|
+
|
70
|
+
exit 0
|
71
|
+
|
data/bin/setup
ADDED
@@ -0,0 +1,23 @@
|
|
1
|
+
$LOAD_PATH.unshift File.expand_path("../../lib", __FILE__)
|
2
|
+
require "resquire"
|
3
|
+
|
4
|
+
# you can add gems when you create a new analyzer, as an array
|
5
|
+
analyzer = Resquire::Analyzer.new(:gems => ['colorize', 'packetfu', 'lolize'])
|
6
|
+
|
7
|
+
# you can also add gems individually
|
8
|
+
analyzer.add_gem('pcaprub')
|
9
|
+
# => true
|
10
|
+
|
11
|
+
# or as an array
|
12
|
+
analyzer.add_gems(['ipaddr', 'socket', 'thread'])
|
13
|
+
# => true
|
14
|
+
|
15
|
+
# you can get an array of the redundant gems
|
16
|
+
analyzer.redundant_gems
|
17
|
+
# => ["pcaprub", "ipaddr", "socket", "thread"]
|
18
|
+
|
19
|
+
# or the new optimized gem listing as an array with the redundancies
|
20
|
+
analyzer.optimized_gems
|
21
|
+
# => ["colorize", "lolize", "packetfu"]
|
22
|
+
|
23
|
+
puts analyzer.optimized_gems
|
data/lib/resquire.rb
ADDED
@@ -0,0 +1,40 @@
|
|
1
|
+
require "resquire/version"
|
2
|
+
require "resquire/banner"
|
3
|
+
require "resquire/analyzer"
|
4
|
+
require "resquire/errors"
|
5
|
+
require 'open3'
|
6
|
+
|
7
|
+
module Resquire
|
8
|
+
|
9
|
+
# I'll put my code wherever I want!
|
10
|
+
#
|
11
|
+
# ┬─┐┌─┐┌─┐┌─┐ ┬ ┬┬┬─┐┌─┐
|
12
|
+
# ├┬┘├┤ └─┐│─┼┐│ ││├┬┘├┤
|
13
|
+
# ┴└─└─┘└─┘└─┘└└─┘┴┴└─└─┘
|
14
|
+
# ─────────────────────────────────────────────────────────────────────────
|
15
|
+
# We'll use this area to describe Resquire a little bit to highlight
|
16
|
+
# what we're trying to solve here.
|
17
|
+
#
|
18
|
+
# So, when we require a gem that itself requires many gems; and if
|
19
|
+
# we were to require one of the gems that a gem we've already required
|
20
|
+
# has already required when it was required -- well, we're actually not
|
21
|
+
# requiring the gem with the second ( or third, or fourth, ect ) require.
|
22
|
+
# Thus, all of those other requires would be redundant, since they're
|
23
|
+
# not going anything. In fact, they're simply returning false.
|
24
|
+
#
|
25
|
+
# Example Scenario:
|
26
|
+
# ┌───────────────────────────────────────────────┐
|
27
|
+
# │ pry / irb shell │
|
28
|
+
# ├───────────────────────────────────────────────┤
|
29
|
+
# │ require 'packetfu' │
|
30
|
+
# │ => true │
|
31
|
+
# │ require 'pcaprub' │
|
32
|
+
# │ => false │
|
33
|
+
# └───────────────────────────────────────────────┘
|
34
|
+
# ─────────────────────────────────────────────────────────────────────────
|
35
|
+
# Resquire's Goal:
|
36
|
+
# If we can find these redundant requires, then we can figure out how to
|
37
|
+
# essentiall optimize our requires and make our applications faster. At
|
38
|
+
# least during require time.
|
39
|
+
|
40
|
+
end
|
@@ -0,0 +1,180 @@
|
|
1
|
+
module Resquire
|
2
|
+
|
3
|
+
class Analyzer
|
4
|
+
# gem dependencies, as an array
|
5
|
+
attr_reader :gems
|
6
|
+
|
7
|
+
# When we create a new Analyzer, we can specifiy the
|
8
|
+
# gems we want to work with, but it must be passed
|
9
|
+
# in as an array in the args hash.
|
10
|
+
#
|
11
|
+
# == Typical Usage
|
12
|
+
#
|
13
|
+
# analyzer = Resquire::Analyzer.new(:gems => ['packetfu', 'pcaprub'])
|
14
|
+
#
|
15
|
+
def initialize(args = {})
|
16
|
+
@gems = []
|
17
|
+
@redundant_gems = []
|
18
|
+
if args[:gems]
|
19
|
+
if args[:gems].is_a? Array
|
20
|
+
add_gems(args[:gems])
|
21
|
+
else
|
22
|
+
raise Resquire::ResquireError.new('Dependencies must be initialized as an array!')
|
23
|
+
end
|
24
|
+
end
|
25
|
+
true
|
26
|
+
end
|
27
|
+
|
28
|
+
# We can add gems specified from an array.
|
29
|
+
#
|
30
|
+
# == Typical Usage
|
31
|
+
#
|
32
|
+
# analyzer = Resquire::Analyzer.new
|
33
|
+
# analyzer.add_gems(['packetfu', 'pcaprub'])
|
34
|
+
#
|
35
|
+
def add_gems(gems = [])
|
36
|
+
gems.uniq.each { |gem| @gems << gem }
|
37
|
+
true
|
38
|
+
end
|
39
|
+
|
40
|
+
# We can add one gem at a time as a string.
|
41
|
+
#
|
42
|
+
# == Typical Usage
|
43
|
+
#
|
44
|
+
# analyzer = Resquire::Analyzer.new
|
45
|
+
# analyzer.add_gem('packetfu')
|
46
|
+
# analyzer.add_gem('pcaprub')
|
47
|
+
#
|
48
|
+
def add_gem(gem)
|
49
|
+
@gems << gem
|
50
|
+
@gems = @gems.uniq
|
51
|
+
true
|
52
|
+
end
|
53
|
+
|
54
|
+
# We can check the given permutations that
|
55
|
+
# we will need to cycle through to find gems
|
56
|
+
# that are redundant.
|
57
|
+
#
|
58
|
+
# == Typical Usage
|
59
|
+
#
|
60
|
+
# analyzer = Resquire::Analyzer.new(:gems => ['packetfu', 'pcaprub'])
|
61
|
+
# analyzer.permutations
|
62
|
+
#
|
63
|
+
def permutations(gems = @gems)
|
64
|
+
(1..gems.count).reduce(:*) || 1
|
65
|
+
end
|
66
|
+
|
67
|
+
# We can find the redundant gems from the the analyzer has
|
68
|
+
# to work with, iterating over the possible permutations and returning
|
69
|
+
# an array of redundant gems.
|
70
|
+
#
|
71
|
+
# == Typical Usage
|
72
|
+
#
|
73
|
+
# analyzer = Resquire::Analyzer.new(:gems => ['packetfu', 'pcaprub'])
|
74
|
+
# analyzer.permutations
|
75
|
+
# # => 2
|
76
|
+
#
|
77
|
+
def redundant_gems(args = {})
|
78
|
+
find_redundant_gems_with_gem(args)
|
79
|
+
@count = 0
|
80
|
+
@permutation_count = permutations
|
81
|
+
@progress_bar = args[:progress_bar] || true
|
82
|
+
gems = args[:gems] || @gems
|
83
|
+
redundant = args[:redundant_gems] || @redundant_gems
|
84
|
+
find_redundant_gems(args).empty? ? false : @redundant_gems
|
85
|
+
end
|
86
|
+
|
87
|
+
|
88
|
+
# Once we have figured out the redundant gems, we can easily check out
|
89
|
+
# our optimized gem list which we can now use.
|
90
|
+
#
|
91
|
+
# == Typical Usage
|
92
|
+
#
|
93
|
+
# analyzer = Resquire::Analyzer.new(:gems => ['packetfu', 'pcaprub'])
|
94
|
+
# analyzer.redundant_gems
|
95
|
+
# # => ['pcaprub']
|
96
|
+
# analyzer.optimized_gems
|
97
|
+
# # => ['packetfu']
|
98
|
+
#
|
99
|
+
def optimized_gems
|
100
|
+
optimized_gems = @gems.reject { |gem| @redundant_gems.include? gem }
|
101
|
+
optimized_gems.empty? ? false : optimized_gems.uniq.sort
|
102
|
+
end
|
103
|
+
|
104
|
+
private
|
105
|
+
|
106
|
+
# Used to find redundant gems.
|
107
|
+
def find_redundant_gems(args = {})
|
108
|
+
gems = @gems.reject { |gem| @redundant_gems.include? gem }
|
109
|
+
permutation_count = permutations(gems)
|
110
|
+
@count = 0
|
111
|
+
# shuffle method by default
|
112
|
+
shuffle = args[:shuffle] || true
|
113
|
+
iterate = args[:iterate] || false
|
114
|
+
if shuffle
|
115
|
+
shuffle_permutations(args)
|
116
|
+
elsif iterate
|
117
|
+
shuffle_permutations(args)
|
118
|
+
else
|
119
|
+
iterate_permutations(args)
|
120
|
+
end
|
121
|
+
@redundant_gems
|
122
|
+
end
|
123
|
+
|
124
|
+
# Help find redundant gems using the gem command.
|
125
|
+
def find_redundant_gems_with_gem(args = {})
|
126
|
+
gems = args[:gems] || @gems
|
127
|
+
gems_with_deps = {}
|
128
|
+
gems.each do |gem|
|
129
|
+
output, status = Open3.capture2e("gem dependency #{gem}")
|
130
|
+
next unless status.success?
|
131
|
+
deps = output.split("\n").map(&:strip)
|
132
|
+
deps = deps.reject { |g| g.include? ', development' or g.include? 'Gem ' }
|
133
|
+
deps = deps.map { |x| x.gsub(/\s\(.+\)/, '') }
|
134
|
+
gems_with_deps[gem] = deps
|
135
|
+
end
|
136
|
+
redundant_gems = []
|
137
|
+
gems_with_deps.keys.each do |gem|
|
138
|
+
next if gems_with_deps[gem].empty?
|
139
|
+
gems_with_deps[gem].each do |g|
|
140
|
+
redundant_gems << g if gems_with_deps.keys.include?(g)
|
141
|
+
end
|
142
|
+
end
|
143
|
+
redundant_gems.uniq.each { |gem| @redundant_gems << gem unless @redundant_gems.include?(gem) }
|
144
|
+
@redundant_gems
|
145
|
+
end
|
146
|
+
|
147
|
+
# We can shuffle the permutations, which can make things faster.
|
148
|
+
def shuffle_permutations(args = {})
|
149
|
+
gems = @gems.reject { |gem| @redundant_gems.include? gem }
|
150
|
+
permutation_count = permutations(gems)
|
151
|
+
count = 0
|
152
|
+
gems = gems.permutation.to_a.shuffle
|
153
|
+
gems.each do |gem_group|
|
154
|
+
print "#{count}/#{permutation_count}\r" if @progress_bar
|
155
|
+
redundant_gem, status = Open3.capture2e("ruby lib/template.rb #{gem_group.join(',')}")
|
156
|
+
@redundant_gems << redundant_gem unless status.success?
|
157
|
+
break unless status.success?
|
158
|
+
count += 1
|
159
|
+
end
|
160
|
+
find_redundant_gems(args) unless count == permutation_count
|
161
|
+
@redundant_gems
|
162
|
+
end
|
163
|
+
|
164
|
+
# We can iterate over the permutations, which can make things faster.
|
165
|
+
def iterate_permutations(args = {})
|
166
|
+
gems = @gems.reject { |gem| @redundant_gems.include? gem }
|
167
|
+
permutation_count = permutations(gems)
|
168
|
+
count = 0
|
169
|
+
gems.permutation.each do |gem_group|
|
170
|
+
print "#{count}/#{permutation_count}\r" if @progress_bar
|
171
|
+
redundant_gem, status = Open3.capture2e("ruby lib/template.rb #{gem_group.join(',')}")
|
172
|
+
@redundant_gems << redundant_gem unless status.success?
|
173
|
+
break unless status.success?
|
174
|
+
count += 1
|
175
|
+
end
|
176
|
+
find_redundant_gems(args) unless count == permutation_count
|
177
|
+
@redundant_gems
|
178
|
+
end
|
179
|
+
end
|
180
|
+
end
|
@@ -0,0 +1,17 @@
|
|
1
|
+
module Resquire
|
2
|
+
|
3
|
+
# ResquireError handles the custom error handling for this Gem
|
4
|
+
#
|
5
|
+
# == Example
|
6
|
+
#
|
7
|
+
# # Typical use case
|
8
|
+
# raise ResquireError.new("This is a custom error!")
|
9
|
+
#
|
10
|
+
class ResquireError < StandardError
|
11
|
+
attr_reader :problem
|
12
|
+
def initialize(problem="Willow Run seems to have encountered a problem.")
|
13
|
+
@problem = problem
|
14
|
+
super(@problem)
|
15
|
+
end
|
16
|
+
end
|
17
|
+
end
|
data/lib/template.rb
ADDED
@@ -0,0 +1,14 @@
|
|
1
|
+
gems = ARGV[0]
|
2
|
+
raise "Error: Need to specify gems are first argument!" if gems.nil?
|
3
|
+
gems = gems.split(",")
|
4
|
+
gems.each do |gem|
|
5
|
+
begin
|
6
|
+
unless require gem
|
7
|
+
print "#{gem}"
|
8
|
+
exit 1
|
9
|
+
end
|
10
|
+
rescue => e
|
11
|
+
puts "Probably attempted to require a gem that doesn't exist!: #{gem}"
|
12
|
+
end
|
13
|
+
end
|
14
|
+
exit 0
|
data/resquire.gemspec
ADDED
@@ -0,0 +1,29 @@
|
|
1
|
+
# coding: utf-8
|
2
|
+
lib = File.expand_path('../lib', __FILE__)
|
3
|
+
$LOAD_PATH.unshift(lib) unless $LOAD_PATH.include?(lib)
|
4
|
+
require 'resquire/version'
|
5
|
+
|
6
|
+
Gem::Specification.new do |spec|
|
7
|
+
spec.name = "resquire"
|
8
|
+
spec.version = Resquire::VERSION
|
9
|
+
spec.authors = ["Kent 'picat' Gruber"]
|
10
|
+
spec.email = ["kgruber1@emich.edu"]
|
11
|
+
|
12
|
+
spec.summary = %q{A Ruby gem dependency analysis tool to help find redundancies and increase performance.}
|
13
|
+
spec.description = %q{Reduce your redundant gem depenencies with resquire, which figures out which gems are redundant so you can require less gems for your ruby projects while still retaining the same functionality! By reducing redundant gems, you can make your application faster!}
|
14
|
+
spec.homepage = "https://github.com/picatz/resquire"
|
15
|
+
spec.license = "MIT"
|
16
|
+
|
17
|
+
spec.files = `git ls-files -z`.split("\x0").reject { |f| f.match(%r{^(test|spec|features)/}) }
|
18
|
+
spec.bindir = "bin"
|
19
|
+
spec.executable = "resquire"
|
20
|
+
spec.require_paths = ["lib"]
|
21
|
+
|
22
|
+
spec.add_dependency "colorize"
|
23
|
+
spec.add_dependency "lolize"
|
24
|
+
spec.add_dependency "trollop"
|
25
|
+
|
26
|
+
spec.add_development_dependency "bundler", "~> 1.13"
|
27
|
+
spec.add_development_dependency "rake", "~> 10.0"
|
28
|
+
spec.add_development_dependency "rspec", "~> 3.0"
|
29
|
+
end
|
metadata
ADDED
@@ -0,0 +1,152 @@
|
|
1
|
+
--- !ruby/object:Gem::Specification
|
2
|
+
name: resquire
|
3
|
+
version: !ruby/object:Gem::Version
|
4
|
+
version: 1.0.0
|
5
|
+
platform: ruby
|
6
|
+
authors:
|
7
|
+
- Kent 'picat' Gruber
|
8
|
+
autorequire:
|
9
|
+
bindir: bin
|
10
|
+
cert_chain: []
|
11
|
+
date: 2016-12-11 00:00:00.000000000 Z
|
12
|
+
dependencies:
|
13
|
+
- !ruby/object:Gem::Dependency
|
14
|
+
name: colorize
|
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: lolize
|
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: trollop
|
43
|
+
requirement: !ruby/object:Gem::Requirement
|
44
|
+
requirements:
|
45
|
+
- - '>='
|
46
|
+
- !ruby/object:Gem::Version
|
47
|
+
version: '0'
|
48
|
+
type: :runtime
|
49
|
+
prerelease: false
|
50
|
+
version_requirements: !ruby/object:Gem::Requirement
|
51
|
+
requirements:
|
52
|
+
- - '>='
|
53
|
+
- !ruby/object:Gem::Version
|
54
|
+
version: '0'
|
55
|
+
- !ruby/object:Gem::Dependency
|
56
|
+
name: bundler
|
57
|
+
requirement: !ruby/object:Gem::Requirement
|
58
|
+
requirements:
|
59
|
+
- - ~>
|
60
|
+
- !ruby/object:Gem::Version
|
61
|
+
version: '1.13'
|
62
|
+
type: :development
|
63
|
+
prerelease: false
|
64
|
+
version_requirements: !ruby/object:Gem::Requirement
|
65
|
+
requirements:
|
66
|
+
- - ~>
|
67
|
+
- !ruby/object:Gem::Version
|
68
|
+
version: '1.13'
|
69
|
+
- !ruby/object:Gem::Dependency
|
70
|
+
name: rake
|
71
|
+
requirement: !ruby/object:Gem::Requirement
|
72
|
+
requirements:
|
73
|
+
- - ~>
|
74
|
+
- !ruby/object:Gem::Version
|
75
|
+
version: '10.0'
|
76
|
+
type: :development
|
77
|
+
prerelease: false
|
78
|
+
version_requirements: !ruby/object:Gem::Requirement
|
79
|
+
requirements:
|
80
|
+
- - ~>
|
81
|
+
- !ruby/object:Gem::Version
|
82
|
+
version: '10.0'
|
83
|
+
- !ruby/object:Gem::Dependency
|
84
|
+
name: rspec
|
85
|
+
requirement: !ruby/object:Gem::Requirement
|
86
|
+
requirements:
|
87
|
+
- - ~>
|
88
|
+
- !ruby/object:Gem::Version
|
89
|
+
version: '3.0'
|
90
|
+
type: :development
|
91
|
+
prerelease: false
|
92
|
+
version_requirements: !ruby/object:Gem::Requirement
|
93
|
+
requirements:
|
94
|
+
- - ~>
|
95
|
+
- !ruby/object:Gem::Version
|
96
|
+
version: '3.0'
|
97
|
+
description: Reduce your redundant gem depenencies with resquire, which figures out
|
98
|
+
which gems are redundant so you can require less gems for your ruby projects while
|
99
|
+
still retaining the same functionality! By reducing redundant gems, you can make
|
100
|
+
your application faster!
|
101
|
+
email:
|
102
|
+
- kgruber1@emich.edu
|
103
|
+
executables:
|
104
|
+
- resquire
|
105
|
+
extensions: []
|
106
|
+
extra_rdoc_files: []
|
107
|
+
files:
|
108
|
+
- .gitignore
|
109
|
+
- .rspec
|
110
|
+
- .travis.yml
|
111
|
+
- CODE_OF_CONDUCT.md
|
112
|
+
- Gemfile
|
113
|
+
- LICENSE.txt
|
114
|
+
- README.md
|
115
|
+
- Rakefile
|
116
|
+
- bin/console
|
117
|
+
- bin/resquire
|
118
|
+
- bin/setup
|
119
|
+
- examples/analyzer.rb
|
120
|
+
- lib/resquire.rb
|
121
|
+
- lib/resquire/analyzer.rb
|
122
|
+
- lib/resquire/banner.rb
|
123
|
+
- lib/resquire/errors.rb
|
124
|
+
- lib/resquire/version.rb
|
125
|
+
- lib/template.rb
|
126
|
+
- resquire.gemspec
|
127
|
+
homepage: https://github.com/picatz/resquire
|
128
|
+
licenses:
|
129
|
+
- MIT
|
130
|
+
metadata: {}
|
131
|
+
post_install_message:
|
132
|
+
rdoc_options: []
|
133
|
+
require_paths:
|
134
|
+
- lib
|
135
|
+
required_ruby_version: !ruby/object:Gem::Requirement
|
136
|
+
requirements:
|
137
|
+
- - '>='
|
138
|
+
- !ruby/object:Gem::Version
|
139
|
+
version: '0'
|
140
|
+
required_rubygems_version: !ruby/object:Gem::Requirement
|
141
|
+
requirements:
|
142
|
+
- - '>='
|
143
|
+
- !ruby/object:Gem::Version
|
144
|
+
version: '0'
|
145
|
+
requirements: []
|
146
|
+
rubyforge_project:
|
147
|
+
rubygems_version: 2.6.8
|
148
|
+
signing_key:
|
149
|
+
specification_version: 4
|
150
|
+
summary: A Ruby gem dependency analysis tool to help find redundancies and increase
|
151
|
+
performance.
|
152
|
+
test_files: []
|