Skip to content

Commit 0c0c74d

Browse files
committed
Grab Gemfile.lock lines once at top of analysis
1 parent 3bad277 commit 0c0c74d

File tree

2 files changed

+9
-5
lines changed

2 files changed

+9
-5
lines changed

lib/cc/engine/bundler_audit/analyzer.rb

Lines changed: 5 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -13,7 +13,7 @@ def run
1313
if gemfile_lock_exists?
1414
Dir.chdir(directory) do
1515
Bundler::Audit::Scanner.new.scan do |vulnerability|
16-
result = Result.new(vulnerability, File.open(gemfile_lock_path))
16+
result = Result.new(vulnerability, gemfile_lock_lines)
1717
issue = result.to_issue
1818

1919
io.print("#{issue.to_json}\0")
@@ -28,6 +28,10 @@ def run
2828

2929
attr_reader :directory, :io
3030

31+
def gemfile_lock_lines
32+
@gemfile_lock_lines ||= File.open(gemfile_lock_path).lines.to_a
33+
end
34+
3135
def gemfile_lock_exists?
3236
File.exist?(gemfile_lock_path)
3337
end

lib/cc/engine/bundler_audit/result.rb

Lines changed: 4 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -9,10 +9,10 @@ class Result
99
low: "info",
1010
}.freeze
1111

12-
def initialize(result, gemfile_lock)
12+
def initialize(result, gemfile_lock_lines)
1313
@gem = result.gem
1414
@advisory = result.advisory
15-
@gemfile_lock = gemfile_lock
15+
@gemfile_lock_lines = gemfile_lock_lines
1616
end
1717

1818
def to_issue
@@ -38,7 +38,7 @@ def to_issue
3838

3939
private
4040

41-
attr_reader :advisory, :gem, :gemfile_lock
41+
attr_reader :advisory, :gem, :gemfile_lock_lines
4242

4343
def content_body
4444
[
@@ -51,7 +51,7 @@ def content_body
5151

5252
def line_number
5353
@line_number ||= begin
54-
gemfile_lock.find_index do |line|
54+
gemfile_lock_lines.find_index do |line|
5555
(match = GEM_REGEX.match(line)) && match[:name] == gem.name
5656
end + 1
5757
end

0 commit comments

Comments
 (0)