Skip to content

Commit f8a0d17

Browse files
martinemdedeivid-rodriguez
authored andcommitted
Merge pull request #6933 from rubygems/martinemde/lockfile-parser-refactor
Unify LockfileParser loading of SPECS section (cherry picked from commit 46113c1)
1 parent 40fd20b commit f8a0d17

File tree

4 files changed

+7
-18
lines changed

4 files changed

+7
-18
lines changed

bundler/lib/bundler/lockfile_parser.rb

Lines changed: 3 additions & 15 deletions
Original file line numberDiff line numberDiff line change
@@ -110,21 +110,9 @@ def may_include_redundant_platform_specific_gems?
110110
def parse_source(line)
111111
case line
112112
when SPECS
113-
case @type
114-
when PATH
115-
@current_source = TYPES[@type].from_lock(@opts)
116-
@sources << @current_source
117-
when GIT
118-
@current_source = TYPES[@type].from_lock(@opts)
119-
@sources << @current_source
120-
when GEM
121-
@opts["remotes"] = Array(@opts.delete("remote")).reverse
122-
@current_source = TYPES[@type].from_lock(@opts)
123-
@sources << @current_source
124-
when PLUGIN
125-
@current_source = Plugin.source_from_lock(@opts)
126-
@sources << @current_source
127-
end
113+
return unless TYPES.key?(@type)
114+
@current_source = TYPES[@type].from_lock(@opts)
115+
@sources << @current_source
128116
when OPTIONS
129117
value = $2
130118
value = true if value == "true"

bundler/lib/bundler/plugin.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -197,7 +197,7 @@ def source(name)
197197
# @param [Hash] The options that are present in the lock file
198198
# @return [API::Source] the instance of the class that handles the source
199199
# type passed in locked_opts
200-
def source_from_lock(locked_opts)
200+
def from_lock(locked_opts)
201201
src = source(locked_opts["type"])
202202

203203
src.new(locked_opts.merge("uri" => locked_opts["remote"]))

bundler/lib/bundler/source/rubygems.rb

Lines changed: 1 addition & 0 deletions
Original file line numberDiff line numberDiff line change
@@ -88,6 +88,7 @@ def options
8888
end
8989

9090
def self.from_lock(options)
91+
options["remotes"] = Array(options.delete("remote")).reverse
9192
new(options)
9293
end
9394

bundler/spec/bundler/plugin_spec.rb

Lines changed: 2 additions & 2 deletions
Original file line numberDiff line numberDiff line change
@@ -225,7 +225,7 @@
225225
end
226226
end
227227

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

237237
expect(SClass).to receive(:new).
238238
with(hash_including("type" => "l_source", "uri" => "xyz", "other" => "random")) { s_instance }
239-
expect(subject.source_from_lock(opts)).to be(s_instance)
239+
expect(subject.from_lock(opts)).to be(s_instance)
240240
end
241241
end
242242

0 commit comments

Comments
 (0)