gem_bench 1.0.5 → 2.0.0
Sign up to get free protection for your applications and to get access to all the features.
- checksums.yaml +4 -4
- checksums.yaml.gz.sig +0 -0
- data/{CHANGELOG → CHANGELOG.md} +47 -16
- data/CODE_OF_CONDUCT.md +84 -0
- data/CONTRIBUTING.md +46 -0
- data/README.md +46 -36
- data/SECURITY.md +14 -0
- data/lib/gem_bench/gemfile_line_tokenizer.rb +59 -55
- data/lib/gem_bench/player.rb +38 -33
- data/lib/gem_bench/scout.rb +19 -20
- data/lib/gem_bench/strict_version_gem.rb +16 -21
- data/lib/gem_bench/strict_version_requirement.rb +26 -30
- data/lib/gem_bench/team.rb +120 -81
- data/lib/gem_bench/version.rb +3 -1
- data/lib/gem_bench.rb +21 -8
- data.tar.gz.sig +1 -0
- metadata +199 -32
- metadata.gz.sig +0 -0
- data/.byebug_history +0 -44
- data/.gitignore +0 -16
- data/.rspec +0 -2
- data/.travis.yml +0 -9
- data/Gemfile +0 -12
- data/Rakefile +0 -6
- data/bin/console +0 -14
- data/bin/setup +0 -8
- data/gem_bench.gemspec +0 -36
data/lib/gem_bench/player.rb
CHANGED
@@ -21,49 +21,56 @@ module GemBench
|
|
21
21
|
|
22
22
|
def set_starter(file_path, line_match: nil)
|
23
23
|
return false if file_path =~ exclude_file_pattern
|
24
|
+
|
24
25
|
# Some gems may have zero files to check, as they may be using gem as a
|
25
26
|
# delivery system for shell scripts! As such we need to check which
|
26
27
|
# gems got checked, and which had nothing to check
|
27
28
|
@checked = true
|
28
29
|
line_match ||= GemBench::RAILTIE_REGEX
|
29
|
-
scan =
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
38
|
-
|
39
|
-
|
30
|
+
scan = if GemBench::DO_NOT_SCAN.include?(name)
|
31
|
+
false
|
32
|
+
else
|
33
|
+
begin
|
34
|
+
File.read(file_path).encode(
|
35
|
+
"utf-8",
|
36
|
+
invalid: :replace,
|
37
|
+
undef: :replace,
|
38
|
+
replace: "_",
|
39
|
+
) =~ line_match
|
40
|
+
rescue ArgumentError => e
|
41
|
+
if e.message =~ /invalid byte sequence/
|
42
|
+
puts "[GemBench] checking #{file_path} failed due to unparseable file content"
|
43
|
+
false # Assume the likelihood of files with encoding issues that also contain railtie to be low, so: false.
|
40
44
|
end
|
41
45
|
end
|
42
46
|
end
|
43
|
-
|
44
|
-
|
45
|
-
|
47
|
+
|
48
|
+
stats << [file_path, scan] if scan
|
49
|
+
self.state = if !!scan
|
50
|
+
GemBench::PLAYER_STATES[:starter]
|
51
|
+
else
|
46
52
|
GemBench::PLAYER_STATES[:bench]
|
53
|
+
end
|
47
54
|
end
|
48
55
|
|
49
56
|
def starter?
|
50
|
-
|
57
|
+
state == GemBench::PLAYER_STATES[:starter]
|
51
58
|
end
|
52
59
|
|
53
60
|
def to_s(format = :name)
|
54
61
|
case format
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
|
66
|
-
|
62
|
+
when :name
|
63
|
+
name
|
64
|
+
when :v
|
65
|
+
"#{name} v#{version}"
|
66
|
+
when :semver
|
67
|
+
"gem '#{name}', '~> #{semver}'"
|
68
|
+
when :locked
|
69
|
+
"gem '#{name}', '#{version}'"
|
70
|
+
when :legacy # when depending on legacy gems, you specifically want to not upgrade, except patches.
|
71
|
+
"gem '#{name}', '~> #{version}'"
|
72
|
+
when :upgrade # when upgrading, and testing gem compatibility you want to try anything newer
|
73
|
+
"gem '#{name}', '>= #{version}'"
|
67
74
|
end
|
68
75
|
end
|
69
76
|
|
@@ -73,17 +80,15 @@ module GemBench
|
|
73
80
|
|
74
81
|
def semver
|
75
82
|
ver = version
|
76
|
-
until ver.split(".").length <= SEMVER_SPLIT_ON_POINT_LENGTH
|
77
|
-
ver = ver[0..(ver.rindex(".")-1)]
|
78
|
-
end
|
83
|
+
ver = ver[0..(ver.rindex(".") - 1)] until ver.split(".").length <= SEMVER_SPLIT_ON_POINT_LENGTH
|
79
84
|
ver
|
80
85
|
end
|
81
86
|
|
82
87
|
def how
|
83
|
-
case
|
84
|
-
when GemBench::PLAYER_STATES[:starter]
|
88
|
+
case state
|
89
|
+
when GemBench::PLAYER_STATES[:starter]
|
85
90
|
to_s(:semver)
|
86
|
-
when GemBench::PLAYER_STATES[:bench]
|
91
|
+
when GemBench::PLAYER_STATES[:bench]
|
87
92
|
"#{to_s(:semver)}, require: false"
|
88
93
|
else
|
89
94
|
if checked
|
data/lib/gem_bench/scout.rb
CHANGED
@@ -3,13 +3,14 @@
|
|
3
3
|
module GemBench
|
4
4
|
class Scout
|
5
5
|
attr_reader :gem_paths, :gemfile_path, :gemfile_lines, :gemfile_trash, :loaded_gems
|
6
|
+
|
6
7
|
def initialize(check_gemfile: nil)
|
7
8
|
@check_gemfile = check_gemfile.nil? ? true : check_gemfile
|
8
9
|
@gemfile_path = "#{Dir.pwd}/Gemfile"
|
9
10
|
gem_lookup_paths_from_bundler
|
10
11
|
gem_lines_from_gemfile
|
11
12
|
# 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
|
+
@loaded_gems = Gem.loaded_specs.values.map { |x| [x.name, x.version.to_s] }
|
13
14
|
end
|
14
15
|
|
15
16
|
def check_gemfile?
|
@@ -19,23 +20,21 @@ module GemBench
|
|
19
20
|
private
|
20
21
|
|
21
22
|
def gem_lookup_paths_from_bundler
|
22
|
-
|
23
|
-
|
24
|
-
|
25
|
-
|
26
|
-
|
27
|
-
|
28
|
-
|
29
|
-
|
30
|
-
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
@gem_paths = [] unless @gem_paths.is_a?(Array)
|
38
|
-
end
|
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)
|
39
38
|
end
|
40
39
|
|
41
40
|
def gem_lines_from_gemfile
|
@@ -44,8 +43,8 @@ module GemBench
|
|
44
43
|
# Get all lines as an array
|
45
44
|
all_lines = file.readlines
|
46
45
|
# 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
|
46
|
+
@gemfile_trash, @gemfile_lines = all_lines.partition { |x| x =~ GemBench::TRASH_REGEX }
|
47
|
+
@gemfile_trash.reject! { |x| x == "\n" } # remove blank lines
|
49
48
|
else
|
50
49
|
@gemfile_trash = []
|
51
50
|
@gemfile_lines = []
|
@@ -1,25 +1,20 @@
|
|
1
1
|
module GemBench
|
2
2
|
class StrictVersionGem
|
3
|
-
attr_reader :name
|
4
|
-
attr_reader :version
|
5
|
-
attr_reader :version_type
|
6
|
-
attr_reader :valid
|
7
|
-
attr_reader :relevant_lines
|
8
|
-
attr_reader :index
|
9
|
-
attr_reader :tokenized_line
|
3
|
+
attr_reader :name, :version, :version_type, :valid, :relevant_lines, :index, :tokenized_line
|
10
4
|
|
11
5
|
class << self
|
12
6
|
def from_line(all_lines, line, index, opts = {})
|
13
7
|
tokenized_line = GemfileLineTokenizer.new(all_lines, line, index)
|
14
|
-
return
|
8
|
+
return unless tokenized_line.is_gem
|
9
|
+
|
15
10
|
new(
|
16
|
-
|
17
|
-
|
18
|
-
|
19
|
-
|
20
|
-
|
21
|
-
|
22
|
-
|
11
|
+
tokenized_line.name,
|
12
|
+
tokenized_line.version,
|
13
|
+
tokenized_line.version_type,
|
14
|
+
tokenized_line.valid,
|
15
|
+
tokenized_line.relevant_lines,
|
16
|
+
tokenized_line.index,
|
17
|
+
(opts[:debug] == true) ? tokenized_line : nil,
|
23
18
|
)
|
24
19
|
end
|
25
20
|
end
|
@@ -43,12 +38,12 @@ module GemBench
|
|
43
38
|
end
|
44
39
|
|
45
40
|
def to_s
|
46
|
-
|
47
|
-
Gem: #{name}
|
48
|
-
Line Number: #{index}
|
49
|
-
Version: #{version.inspect}
|
50
|
-
Relevant Gemfile Lines:
|
51
|
-
#{relevant_lines.join("\n")}
|
41
|
+
<<~EOS
|
42
|
+
Gem: #{name}
|
43
|
+
Line Number: #{index}
|
44
|
+
Version: #{version.inspect}
|
45
|
+
Relevant Gemfile Lines:
|
46
|
+
#{relevant_lines.join("\n")}
|
52
47
|
EOS
|
53
48
|
end
|
54
49
|
end
|
@@ -1,10 +1,6 @@
|
|
1
1
|
module GemBench
|
2
2
|
class StrictVersionRequirement
|
3
|
-
attr_reader :gemfile_path
|
4
|
-
attr_reader :gems
|
5
|
-
attr_reader :starters
|
6
|
-
attr_reader :benchers
|
7
|
-
attr_reader :verbose
|
3
|
+
attr_reader :gemfile_path, :gems, :starters, :benchers, :verbose
|
8
4
|
|
9
5
|
def initialize(options = {})
|
10
6
|
@gemfile_path = "#{Dir.pwd}/Gemfile"
|
@@ -18,14 +14,14 @@ module GemBench
|
|
18
14
|
@gems << gem if gem
|
19
15
|
end
|
20
16
|
|
21
|
-
@starters, @benchers = @gems.partition {|x| x.valid? }
|
17
|
+
@starters, @benchers = @gems.partition { |x| x.valid? }
|
22
18
|
# Remove all the commented || blank lines
|
23
19
|
@verbose = options[:verbose]
|
24
|
-
self.print if
|
20
|
+
self.print if verbose
|
25
21
|
end
|
26
22
|
|
27
23
|
def versions_present?
|
28
|
-
gems.detect {|x| !x.valid? }.nil?
|
24
|
+
gems.detect { |x| !x.valid? }.nil?
|
29
25
|
end
|
30
26
|
|
31
27
|
def list_missing_version_constraints
|
@@ -33,34 +29,34 @@ module GemBench
|
|
33
29
|
end
|
34
30
|
|
35
31
|
def find(name)
|
36
|
-
gems.detect {|x| x.name == name }
|
32
|
+
gems.detect { |x| x.name == name }
|
37
33
|
end
|
38
34
|
|
39
35
|
def gem_at(index)
|
40
|
-
gems.detect {|x| x.index == index }
|
36
|
+
gems.detect { |x| x.index == index }
|
41
37
|
end
|
42
38
|
|
43
39
|
def print
|
44
|
-
using_path = benchers.count {|x| x.is_type?(:path) }
|
45
|
-
puts
|
46
|
-
|
47
|
-
The gems that need to be improved are:
|
48
|
-
|
49
|
-
#{benchers.map(&:to_s).join("\n")}
|
50
|
-
|
51
|
-
There are #{starters.length} gems that have valid strict version constraints.
|
52
|
-
Of those:
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
There are #{benchers.length} gems that do not have strict version constraints.
|
58
|
-
Of those:
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
EOS
|
40
|
+
using_path = benchers.count { |x| x.is_type?(:path) }
|
41
|
+
puts <<~EOS
|
42
|
+
#{" "}
|
43
|
+
The gems that need to be improved are:
|
44
|
+
|
45
|
+
#{benchers.map(&:to_s).join("\n")}
|
46
|
+
|
47
|
+
There are #{starters.length} gems that have valid strict version constraints.
|
48
|
+
Of those:
|
49
|
+
#{starters.count { |x| x.is_type?(:constraint) }} use primary constraints (e.g. '~> 1.2.3').
|
50
|
+
#{starters.count { |x| x.is_type?(:git_ref) }} use git ref constraints.
|
51
|
+
#{starters.count { |x| x.is_type?(:git_tag) }} use git tag constraints.
|
52
|
+
|
53
|
+
There are #{benchers.length} gems that do not have strict version constraints.
|
54
|
+
Of those:
|
55
|
+
#{benchers.count { |x| x.is_type?(:git_branch) }} use git branch constraints.
|
56
|
+
#{benchers.count { |x| x.is_type?(:git) }} use some other form of git constraint considered not strict enough.
|
57
|
+
#{benchers.count { |x| x.is_type?(:unknown) }} gems seem to not have any constraint at all.
|
58
|
+
#{using_path} gems are using a local path. #{"WARNING!!!" if using_path > 0}
|
59
|
+
EOS
|
64
60
|
end
|
65
61
|
end
|
66
62
|
end
|
data/lib/gem_bench/team.rb
CHANGED
@@ -2,14 +2,37 @@ require "forwardable"
|
|
2
2
|
|
3
3
|
module GemBench
|
4
4
|
class Team
|
5
|
-
EXCLUDE = [
|
6
|
-
|
7
|
-
|
5
|
+
EXCLUDE = %w[
|
6
|
+
bundler
|
7
|
+
gem_bench
|
8
|
+
i18n-airbrake
|
9
|
+
devise-async
|
10
|
+
km
|
11
|
+
vestal_versions
|
12
|
+
omniauth-facebook
|
13
|
+
flag_shih_tzu
|
14
|
+
pry-remote
|
15
|
+
koala
|
16
|
+
simple_form
|
17
|
+
thumbs_up
|
18
|
+
memoist
|
19
|
+
cancan
|
20
|
+
friendly_id
|
21
|
+
faker
|
22
|
+
]
|
8
23
|
# A comment preceding the require: false anywhere on the line should not be considered an active require: false
|
9
24
|
extend Forwardable
|
10
25
|
def_delegators :@scout, :gem_paths, :gemfile_path, :check_gemfile?, :loaded_gems
|
11
26
|
attr_reader :scout, :look_for_regex
|
12
|
-
attr_accessor :all,
|
27
|
+
attr_accessor :all,
|
28
|
+
:excluded,
|
29
|
+
:starters,
|
30
|
+
:benchers,
|
31
|
+
:verbose,
|
32
|
+
:gemfile_lines,
|
33
|
+
:trash_lines,
|
34
|
+
:current_gemfile_suggestions,
|
35
|
+
:bad_ideas
|
13
36
|
|
14
37
|
def initialize(options = {})
|
15
38
|
@look_for_regex = options[:look_for_regex]
|
@@ -20,94 +43,104 @@ module GemBench
|
|
20
43
|
@scout = GemBench::Scout.new(check_gemfile: options[:check_gemfile] || benching?)
|
21
44
|
@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
45
|
# 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 = " + #{
|
46
|
+
@excluded, @all = @scout.loaded_gems.partition { |x| EXCLUDE.include?(x[0]) }
|
47
|
+
exclusions = " + #{excluded.length} loaded gems which GemBench is configured to ignore.\n" if @excluded.length > 0
|
25
48
|
@starters = []
|
26
49
|
@benchers = []
|
27
50
|
@current_gemfile_suggestions = []
|
28
51
|
@verbose = options[:verbose]
|
29
|
-
|
52
|
+
check_all
|
30
53
|
@bad_ideas = if benching?
|
31
|
-
|
32
|
-
|
33
|
-
|
34
|
-
|
35
|
-
|
36
|
-
|
37
|
-
|
54
|
+
if options[:bad_ideas]
|
55
|
+
true
|
56
|
+
else
|
57
|
+
check_gemfile? ? false : !(options[:bad_ideas] == false)
|
58
|
+
end
|
59
|
+
else
|
60
|
+
false
|
61
|
+
end
|
62
|
+
puts "[GemBench] Will search for gems in #{gem_paths.inspect}\n#{if benching?
|
63
|
+
@scout.check_gemfile? ? "[GemBench] Will check Gemfile at #{gemfile_path}.\n" : "[GemBench] No Gemfile found.\n"
|
64
|
+
else
|
65
|
+
""
|
66
|
+
end}#{bad_ideas ? "[GemBench] Will show bad ideas. Be Careful.\n" : ""}[GemBench] Detected #{all.length} loaded gems#{exclusions}"
|
67
|
+
compare_gemfile if benching? && @scout.check_gemfile?
|
68
|
+
self.print if verbose
|
38
69
|
end
|
39
70
|
|
40
71
|
def list_starters(format: :name)
|
41
|
-
starters.map {|starter| starter.to_s(format)}
|
72
|
+
starters.map { |starter| starter.to_s(format) }
|
42
73
|
end
|
43
74
|
|
44
75
|
def print
|
45
|
-
string =
|
46
|
-
if
|
76
|
+
string = ""
|
77
|
+
if all.empty?
|
47
78
|
string << nothing
|
48
|
-
elsif
|
79
|
+
elsif starters.empty?
|
49
80
|
string << if benching?
|
50
|
-
|
51
|
-
|
52
|
-
|
53
|
-
|
54
|
-
|
55
|
-
|
56
|
-
|
57
|
-
|
58
|
-
|
59
|
-
|
60
|
-
|
61
|
-
|
62
|
-
|
63
|
-
|
64
|
-
|
65
|
-
string << "\t\t#{stat[0]}:#{stat[1]}\n"
|
66
|
-
end
|
67
|
-
end
|
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
|
74
|
-
self.starters.each_with_index do |starter, index|
|
75
|
-
string << "#{starter.info(index + 1)}\n"
|
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
|
81
|
+
"[GemBench] Found no gems that need to load at boot time.\n"
|
82
|
+
else
|
83
|
+
"[GemBench] Found no gems containing #{look_for_regex} in Ruby code.\n"
|
84
|
+
end
|
85
|
+
elsif starters.length > 0
|
86
|
+
string << "\n#{GemBench::USAGE}" unless check_gemfile?
|
87
|
+
string << if benching?
|
88
|
+
"[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"
|
89
|
+
else
|
90
|
+
"[GemBench] We found #{look_for_regex} in the following files.\n\n"
|
91
|
+
end
|
92
|
+
starters.each do |starter|
|
93
|
+
string << "\t#{starter}:\n"
|
94
|
+
starter.stats.each do |stat|
|
95
|
+
string << "\t\t#{stat[0]}:#{stat[1]}\n"
|
82
96
|
end
|
97
|
+
end
|
98
|
+
if benching?
|
99
|
+
string << "[GemBench] If you want to check for false positives, the files to check for Railties and Engines are listed above.\n"
|
100
|
+
end
|
101
|
+
string << if benching?
|
102
|
+
"[GemBench] #{starters.length} out of #{all.length} evaluated gems actually need to be loaded at boot time. They are:\n"
|
83
103
|
else
|
84
|
-
|
85
|
-
|
104
|
+
"[GemBench] #{starters.length} out of #{all.length} evaluated gems contain #{look_for_regex}. They are:\n"
|
105
|
+
end
|
106
|
+
starters.each_with_index do |starter, index|
|
107
|
+
string << "#{starter.info(index + 1)}\n"
|
86
108
|
end
|
109
|
+
if extra_verbose? && !benching? && benchers.length > 0
|
110
|
+
string << "[GemBench] #{benchers.length} out of #{all.length} evaluated gems did not contain #{look_for_regex}. They are:\n"
|
111
|
+
benchers.each_with_index do |bencher, index|
|
112
|
+
string << "#{bencher.info(index + 1)}\n"
|
113
|
+
end
|
114
|
+
end
|
115
|
+
else
|
116
|
+
string << "[GemBench] Congrats! All gems appear clean.\n"
|
117
|
+
string << "\n#{GemBench::USAGE}" unless check_gemfile?
|
87
118
|
end
|
88
119
|
if check_gemfile? && benching?
|
89
|
-
if
|
90
|
-
string << "[GemBench] Evaluated #{
|
91
|
-
|
120
|
+
if current_gemfile_suggestions.length > 0
|
121
|
+
string << "[GemBench] Evaluated #{all.length} gems and Gemfile at #{gemfile_path}.\n[GemBench] Here are #{current_gemfile_suggestions.length} suggestions for improvement:\n"
|
122
|
+
current_gemfile_suggestions.each_with_index do |player, index|
|
92
123
|
string << "#{player.suggest(index + 1)}\n"
|
93
124
|
end
|
94
125
|
else
|
95
|
-
string <<
|
126
|
+
string << strike_out
|
96
127
|
end
|
97
128
|
end
|
98
129
|
|
99
|
-
if benching? &&
|
130
|
+
if benching? && bad_ideas
|
100
131
|
# Only bad ideas if you are evaluating an actual Gemfile. If just evaluating loaded gems, then info is fine.
|
101
|
-
string <<
|
132
|
+
string << prepare_bad_ideas
|
102
133
|
end
|
103
134
|
|
104
135
|
puts string
|
105
136
|
end
|
106
137
|
|
107
138
|
def strike_out
|
108
|
-
check_gemfile?
|
109
|
-
"[GemBench] Evaluated #{
|
110
|
-
|
139
|
+
if check_gemfile?
|
140
|
+
"[GemBench] Evaluated #{all.length} gems against your Gemfile but found no primary dependencies which can safely skip require on boot (require: false).\n"
|
141
|
+
else
|
142
|
+
"[GemBench] Evaluated #{all.length} gems but found none which can safely skip require on boot (require: false).\n"
|
143
|
+
end
|
111
144
|
end
|
112
145
|
|
113
146
|
def nothing
|
@@ -115,40 +148,46 @@ module GemBench
|
|
115
148
|
end
|
116
149
|
|
117
150
|
def prepare_bad_ideas
|
118
|
-
string =
|
119
|
-
if
|
120
|
-
gemfile_instruction = check_gemfile? ?
|
121
|
-
string << "[GemBench] Evaluated #{
|
122
|
-
|
151
|
+
string = ""
|
152
|
+
if benchers.length > 0
|
153
|
+
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"
|
154
|
+
string << "[GemBench] Evaluated #{all.length} loaded gems and found #{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}"
|
155
|
+
benchers.each_with_index do |player, index|
|
123
156
|
string << "#{player.careful(index + 1)}\n"
|
124
157
|
end
|
125
158
|
else
|
126
|
-
string <<
|
159
|
+
string << strike_out
|
127
160
|
end
|
128
161
|
string
|
129
162
|
end
|
130
163
|
|
131
164
|
def compare_gemfile
|
132
|
-
|
165
|
+
benchers.each do |player|
|
133
166
|
scout.gemfile_lines.each do |line|
|
134
167
|
found = (line =~ player.gemfile_regex)
|
135
|
-
|
136
|
-
|
137
|
-
|
138
|
-
|
139
|
-
|
140
|
-
|
168
|
+
next unless found
|
169
|
+
|
170
|
+
# remove the found line from the array, because no sane person has more than one gem dependency per line... right?
|
171
|
+
line = scout.gemfile_lines.delete_at(scout.gemfile_lines.index(line))
|
172
|
+
# does the line already have require: false?
|
173
|
+
unless line =~ GemBench::REQUIRE_FALSE_REGEX
|
174
|
+
current_gemfile_suggestions << benchers.delete_at(benchers.index(player))
|
141
175
|
end
|
176
|
+
break # outside of the inner loop
|
142
177
|
end
|
143
178
|
end
|
144
179
|
end
|
145
180
|
|
146
181
|
def check_all
|
147
|
-
|
182
|
+
all.each do |player_data|
|
148
183
|
exclude_file_pattern = @exclude_file_pattern_regex_proc.call(player_data[0])
|
149
|
-
player = GemBench::Player.new({
|
150
|
-
|
151
|
-
|
184
|
+
player = GemBench::Player.new({
|
185
|
+
name: player_data[0],
|
186
|
+
version: player_data[1],
|
187
|
+
exclude_file_pattern: exclude_file_pattern,
|
188
|
+
})
|
189
|
+
check(player)
|
190
|
+
add_to_roster(player)
|
152
191
|
end
|
153
192
|
end
|
154
193
|
|
@@ -166,16 +205,16 @@ module GemBench
|
|
166
205
|
|
167
206
|
def add_to_roster(player)
|
168
207
|
if player.starter?
|
169
|
-
|
208
|
+
starters << player
|
170
209
|
else
|
171
|
-
|
210
|
+
benchers << player
|
172
211
|
end
|
173
212
|
end
|
174
213
|
|
175
214
|
private
|
176
215
|
|
177
216
|
def extra_verbose?
|
178
|
-
|
217
|
+
verbose == "extra"
|
179
218
|
end
|
180
219
|
|
181
220
|
def benching?
|
data/lib/gem_bench/version.rb
CHANGED