Skip to content

Commit

Permalink
Merge pull request #6933 from rubygems/martinemde/lockfile-parser-ref…
Browse files Browse the repository at this point in the history
…actor

Unify LockfileParser loading of SPECS section
  • Loading branch information
martinemde committed Sep 12, 2023
2 parents c5aad3f + 5b33e91 commit 46113c1
Show file tree
Hide file tree
Showing 4 changed files with 7 additions and 18 deletions.
18 changes: 3 additions & 15 deletions bundler/lib/bundler/lockfile_parser.rb
Original file line number Diff line number Diff line change
Expand Up @@ -110,21 +110,9 @@ def may_include_redundant_platform_specific_gems?
def parse_source(line)
case line
when SPECS
case @type
when PATH
@current_source = TYPES[@type].from_lock(@opts)
@sources << @current_source
when GIT
@current_source = TYPES[@type].from_lock(@opts)
@sources << @current_source
when GEM
@opts["remotes"] = Array(@opts.delete("remote")).reverse
@current_source = TYPES[@type].from_lock(@opts)
@sources << @current_source
when PLUGIN
@current_source = Plugin.source_from_lock(@opts)
@sources << @current_source
end
return unless TYPES.key?(@type)
@current_source = TYPES[@type].from_lock(@opts)
@sources << @current_source
when OPTIONS
value = $2
value = true if value == "true"
Expand Down
2 changes: 1 addition & 1 deletion bundler/lib/bundler/plugin.rb
Original file line number Diff line number Diff line change
Expand Up @@ -197,7 +197,7 @@ def source(name)
# @param [Hash] The options that are present in the lock file
# @return [API::Source] the instance of the class that handles the source
# type passed in locked_opts
def source_from_lock(locked_opts)
def from_lock(locked_opts)
src = source(locked_opts["type"])

src.new(locked_opts.merge("uri" => locked_opts["remote"]))
Expand Down
1 change: 1 addition & 0 deletions bundler/lib/bundler/source/rubygems.rb
Original file line number Diff line number Diff line change
Expand Up @@ -88,6 +88,7 @@ def options
end

def self.from_lock(options)
options["remotes"] = Array(options.delete("remote")).reverse
new(options)
end

Expand Down
4 changes: 2 additions & 2 deletions bundler/spec/bundler/plugin_spec.rb
Original file line number Diff line number Diff line change
Expand Up @@ -225,7 +225,7 @@
end
end

describe "#source_from_lock" do
describe "#from_lock" do
it "returns instance of registered class initialized with locked opts" do
opts = { "type" => "l_source", "remote" => "xyz", "other" => "random" }
allow(index).to receive(:source_plugin).with("l_source") { "plugin_name" }
Expand All @@ -236,7 +236,7 @@

expect(SClass).to receive(:new).
with(hash_including("type" => "l_source", "uri" => "xyz", "other" => "random")) { s_instance }
expect(subject.source_from_lock(opts)).to be(s_instance)
expect(subject.from_lock(opts)).to be(s_instance)
end
end

Expand Down

0 comments on commit 46113c1

Please sign in to comment.