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.
@@ -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 = begin
30
- if GemBench::DO_NOT_SCAN.include?(name)
31
- false
32
- else
33
- begin
34
- File.read(file_path).encode('utf-8', :invalid => :replace, :undef => :replace, :replace => '_') =~ line_match
35
- rescue ArgumentError => e
36
- if e.message =~ /invalid byte sequence/
37
- puts "[GemBench] checking #{file_path} failed due to unparseable file content"
38
- false # Assume the likelihood of files with encoding issues that also contain railtie to be low, so: false.
39
- end
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
- self.stats << [file_path,scan] if scan
44
- self.state = !!scan ?
45
- GemBench::PLAYER_STATES[:starter] :
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
- self.state == GemBench::PLAYER_STATES[:starter]
57
+ state == GemBench::PLAYER_STATES[:starter]
51
58
  end
52
59
 
53
60
  def to_s(format = :name)
54
61
  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}'"
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 do
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 self.state
84
- when GemBench::PLAYER_STATES[:starter] then
88
+ case state
89
+ when GemBench::PLAYER_STATES[:starter]
85
90
  to_s(:semver)
86
- when GemBench::PLAYER_STATES[:bench] then
91
+ when GemBench::PLAYER_STATES[:bench]
87
92
  "#{to_s(:semver)}, require: false"
88
93
  else
89
94
  if checked
@@ -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
- 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
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 nil unless tokenized_line.is_gem
8
+ return unless tokenized_line.is_gem
9
+
15
10
  new(
16
- tokenized_line.name,
17
- tokenized_line.version,
18
- tokenized_line.version_type,
19
- tokenized_line.valid,
20
- tokenized_line.relevant_lines,
21
- tokenized_line.index,
22
- opts[:debug] == true ? tokenized_line : nil
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
- <<-EOS
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 self.verbose
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 <<-EOS
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
- #{starters.count {|x| x.is_type?(:constraint) }} use primary constraints (e.g. '~> 1.2.3').
54
- #{starters.count {|x| x.is_type?(:git_ref) }} use git ref constraints.
55
- #{starters.count {|x| x.is_type?(:git_tag) }} use git tag constraints.
56
-
57
- There are #{benchers.length} gems that do not have strict version constraints.
58
- Of those:
59
- #{benchers.count {|x| x.is_type?(:git_branch) }} use git branch constraints.
60
- #{benchers.count {|x| x.is_type?(:git) }} use some other form of git constraint considered not strict enough.
61
- #{benchers.count {|x| x.is_type?(:unknown) }} gems seem to not have any constraint at all.
62
- #{using_path} gems are using a local path. #{'WARNING!!!' if using_path > 0}
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
@@ -2,14 +2,37 @@ require "forwardable"
2
2
 
3
3
  module GemBench
4
4
  class Team
5
- EXCLUDE = [ 'bundler','gem_bench','i18n-airbrake','devise-async','km','vestal_versions','omniauth-facebook',
6
- 'flag_shih_tzu','pry-remote','koala','simple_form','thumbs_up','memoist','cancan','friendly_id',
7
- 'faker']
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, :excluded, :starters, :benchers, :verbose, :gemfile_lines, :trash_lines, :current_gemfile_suggestions, :bad_ideas
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 = " + #{self.excluded.length} loaded gems which GemBench is configured to ignore.\n" if @excluded.length > 0
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
- self.check_all
52
+ check_all
30
53
  @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?
37
- self.print if self.verbose
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 self.all.empty?
76
+ string = ""
77
+ if all.empty?
47
78
  string << nothing
48
- elsif self.starters.empty?
79
+ elsif starters.empty?
49
80
  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
54
- else
55
- if self.starters.length > 0
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
62
- self.starters.each do |starter|
63
- string << "\t#{starter}:\n"
64
- starter.stats.each do |stat|
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
- string << "[GemBench] Congrats! All gems appear clean.\n"
85
- string << "\n#{GemBench::USAGE}" unless check_gemfile?
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 self.current_gemfile_suggestions.length > 0
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"
91
- self.current_gemfile_suggestions.each_with_index do |player, index|
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 << self.strike_out
126
+ string << strike_out
96
127
  end
97
128
  end
98
129
 
99
- if benching? && self.bad_ideas
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 << self.prepare_bad_ideas
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 #{self.all.length} gems against your Gemfile but found no primary dependencies which can safely skip require on boot (require: false).\n" :
110
- "[GemBench] Evaluated #{self.all.length} gems but found none which can safely skip require on boot (require: false).\n"
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 self.benchers.length > 0
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"
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}"
122
- self.benchers.each_with_index do |player, index|
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 << self.strike_out
159
+ string << strike_out
127
160
  end
128
161
  string
129
162
  end
130
163
 
131
164
  def compare_gemfile
132
- self.benchers.each do |player|
165
+ benchers.each do |player|
133
166
  scout.gemfile_lines.each do |line|
134
167
  found = (line =~ player.gemfile_regex)
135
- if found
136
- # remove the found line from the array, because no sane person has more than one gem dependency per line... right?
137
- line = scout.gemfile_lines.delete_at(scout.gemfile_lines.index(line))
138
- # does the line already have require: false?
139
- self.current_gemfile_suggestions << self.benchers.delete_at(self.benchers.index(player)) unless line =~ GemBench::REQUIRE_FALSE_REGEX
140
- break # outside of the inner loop
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
- self.all.each do |player_data|
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({name: player_data[0], version: player_data[1], exclude_file_pattern: exclude_file_pattern})
150
- self.check(player)
151
- self.add_to_roster(player)
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
- self.starters << player
208
+ starters << player
170
209
  else
171
- self.benchers << player
210
+ benchers << player
172
211
  end
173
212
  end
174
213
 
175
214
  private
176
215
 
177
216
  def extra_verbose?
178
- self.verbose == "extra"
217
+ verbose == "extra"
179
218
  end
180
219
 
181
220
  def benching?
@@ -1,3 +1,5 @@
1
1
  module GemBench
2
- VERSION = "1.0.5"
2
+ module Version
3
+ VERSION = "2.0.0"
4
+ end
3
5
  end