[rubygems/rubygems] Refactor setting current gemfile in DSL

https://github.com/rubygems/rubygems/commit/b4ecb66224
This commit is contained in:
David Rodríguez 2024-09-05 14:04:30 +02:00 committed by git
parent 1d768ebd71
commit f0b9baa2d6

View File

@ -42,20 +42,16 @@ module Bundler
end end
def eval_gemfile(gemfile, contents = nil) def eval_gemfile(gemfile, contents = nil)
expanded_gemfile_path = Pathname.new(gemfile).expand_path(@gemfile&.parent) with_gemfile(gemfile) do |current_gemfile|
original_gemfile = @gemfile contents ||= Bundler.read_file(current_gemfile)
@gemfile = expanded_gemfile_path instance_eval(contents, current_gemfile, 1)
@gemfiles << expanded_gemfile_path rescue Exception => e # rubocop:disable Lint/RescueException
contents ||= Bundler.read_file(@gemfile.to_s) message = "There was an error " \
instance_eval(contents, @gemfile.to_s, 1) "#{e.is_a?(GemfileEvalError) ? "evaluating" : "parsing"} " \
rescue Exception => e # rubocop:disable Lint/RescueException "`#{File.basename current_gemfile}`: #{e.message}"
message = "There was an error " \
"#{e.is_a?(GemfileEvalError) ? "evaluating" : "parsing"} " \
"`#{File.basename gemfile.to_s}`: #{e.message}"
raise DSLError.new(message, gemfile.to_s, e.backtrace, contents) raise DSLError.new(message, current_gemfile, e.backtrace, contents)
ensure end
@gemfile = original_gemfile
end end
def gemspec(opts = nil) def gemspec(opts = nil)
@ -285,6 +281,16 @@ module Bundler
private private
def with_gemfile(gemfile)
expanded_gemfile_path = Pathname.new(gemfile).expand_path(@gemfile&.parent)
original_gemfile = @gemfile
@gemfile = expanded_gemfile_path
@gemfiles << expanded_gemfile_path
yield @gemfile.to_s
ensure
@gemfile = original_gemfile
end
def add_git_sources def add_git_sources
git_source(:github) do |repo_name| git_source(:github) do |repo_name|
if repo_name =~ GITHUB_PULL_REQUEST_URL if repo_name =~ GITHUB_PULL_REQUEST_URL