Skip to content

Commit 4819d0e

Browse files
dfop02hsbt
authored andcommitted
Refactoring updates
1 parent 29c212a commit 4819d0e

File tree

5 files changed

+27
-17
lines changed

5 files changed

+27
-17
lines changed

bundler/lib/bundler/plugin.rb

Lines changed: 14 additions & 4 deletions
Original file line numberDiff line numberDiff line change
@@ -39,8 +39,9 @@ def install(names, options)
3939
raise InvalidOption, "You cannot specify `--branch` and `--ref` at the same time." if options["branch"] && options["ref"]
4040

4141
specs = Installer.new.install(names, options)
42+
plugins = plugins_to_save(names, specs)
4243

43-
save_plugins names, specs
44+
save_plugins(plugins, specs)
4445
rescue PluginError
4546
specs_to_delete = specs.select {|k, _v| names.include?(k) && !index.commands.values.include?(k) }
4647
specs_to_delete.each_value {|spec| Bundler.rm_rf(spec.full_gem_path) }
@@ -113,10 +114,10 @@ def gemfile_install(gemfile = nil, &inline)
113114

114115
return if definition.dependencies.empty?
115116

116-
plugins = definition.dependencies.map(&:name).reject {|p| index.installed? p }
117117
installed_specs = Installer.new.install_definition(definition)
118+
plugins = plugins_to_save(definition.dependencies.map(&:name), installed_specs)
118119

119-
save_plugins plugins, installed_specs, builder.inferred_plugins
120+
save_plugins(plugins, installed_specs, builder.inferred_plugins)
120121
end
121122
rescue RuntimeError => e
122123
unless e.is_a?(GemfileError)
@@ -142,6 +143,15 @@ def root
142143
end
143144
end
144145

146+
# Return array of plugins that we need save or update the path
147+
# based if was not installed with that version yet
148+
def plugins_to_save(plugins, installed_specs)
149+
plugins.reject do |p|
150+
installed_spec = installed_specs[p]
151+
installed_spec.nil? || index.version_already_installed?(p, installed_spec.version)
152+
end
153+
end
154+
145155
def local_root
146156
Bundler.app_config_path.join("plugin")
147157
end
@@ -253,7 +263,7 @@ def loaded?(plugin)
253263
# @param [Array<String>] names of inferred source plugins that can be ignored
254264
def save_plugins(plugins, specs, optional_plugins = [])
255265
plugins.each do |name|
256-
next if index.installed?(name)
266+
next if index.version_already_installed?(name, specs[name].version)
257267

258268
spec = specs[name]
259269

bundler/lib/bundler/plugin/index.rb

Lines changed: 4 additions & 6 deletions
Original file line numberDiff line numberDiff line change
@@ -111,14 +111,12 @@ def command_plugin(command)
111111
@commands[command]
112112
end
113113

114-
# Plugin cannot be installed and updating to install
114+
# Plugin version is already installed?
115115
def version_already_installed?(name, version)
116-
installed?(name) && !updating?(name, version)
117-
end
116+
plugin_path = @plugin_paths[name]
117+
return false unless plugin_path
118118

119-
# An existing plugin must have a diff version to install again
120-
def updating?(name, version)
121-
version.to_s != @plugin_paths[name][/#{name}-(.*)$/, 1].to_s
119+
File.basename(plugin_path) == "#{name}-#{version}"
122120
end
123121

124122
# Plugin is already installed?

bundler/lib/bundler/plugin/installer.rb

Lines changed: 1 addition & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -114,7 +114,7 @@ def install_from_specs(specs)
114114
# @param [String] name of the plugin gem to search in the source
115115
# @param [String] version of the gem to install
116116
#
117-
# @return [Boolean] true if installed or not updating plugin
117+
# @return [Boolean] true if plugin version already installed
118118
def version_already_installed?(plugin, version)
119119
Index.new.version_already_installed?(plugin, version)
120120
end

bundler/spec/plugins/install_spec.rb

Lines changed: 5 additions & 5 deletions
Original file line numberDiff line numberDiff line change
@@ -89,7 +89,7 @@
8989
expect(out).to include("Installing foo 1.1")
9090

9191
bundle "plugin install foo --source #{file_uri_for(gem_repo2)} --verbose"
92-
expect(out).to include("Using foo 1.1")
92+
expect(out).to_not include("foo 1.1")
9393
end
9494

9595
it "installs when --branch specified" do
@@ -251,7 +251,7 @@ def exec(command, args)
251251
expect(out).to include("Bundle complete!")
252252

253253
expect(the_bundle).to include_gems("rack 1.0.0")
254-
plugin_should_be_installed("foo")
254+
plugin_should_be_installed("foo", version: "1.4.0")
255255

256256
gemfile <<-G
257257
source '#{file_uri_for(gem_repo2)}'
@@ -265,7 +265,7 @@ def exec(command, args)
265265
expect(out).to include("Bundle complete!")
266266

267267
expect(the_bundle).to include_gems("rack 1.0.0")
268-
plugin_should_be_installed("foo")
268+
plugin_should_be_installed("foo", version: "1.5.0")
269269
end
270270

271271
it "downgrade plugins version listed in gemfile" do
@@ -287,7 +287,7 @@ def exec(command, args)
287287
expect(out).to include("Bundle complete!")
288288

289289
expect(the_bundle).to include_gems("rack 1.0.0")
290-
plugin_should_be_installed("foo")
290+
plugin_should_be_installed("foo", version: "1.5.0")
291291

292292
gemfile <<-G
293293
source '#{file_uri_for(gem_repo2)}'
@@ -301,7 +301,7 @@ def exec(command, args)
301301
expect(out).to include("Bundle complete!")
302302

303303
expect(the_bundle).to include_gems("rack 1.0.0")
304-
plugin_should_be_installed("foo")
304+
plugin_should_be_installed("foo", version: "1.4.0")
305305
end
306306

307307
it "install only plugins not installed yet listed in gemfile" do

bundler/spec/support/matchers.rb

Lines changed: 3 additions & 1 deletion
Original file line numberDiff line numberDiff line change
@@ -220,10 +220,12 @@ def indent(string, padding = 4, indent_character = " ")
220220
RSpec::Matchers.define_negated_matcher :not_include_gems, :include_gems
221221
RSpec::Matchers.alias_matcher :include_gem, :include_gems
222222

223-
def plugin_should_be_installed(*names)
223+
def plugin_should_be_installed(*names, version: nil)
224224
names.each do |name|
225225
expect(Bundler::Plugin).to be_installed(name)
226226
path = Pathname.new(Bundler::Plugin.installed?(name))
227+
228+
expect(File.basename(path)).to eq("#{name}-#{version}") unless version.nil?
227229
expect(path + "plugins.rb").to exist
228230
end
229231
end

0 commit comments

Comments
 (0)