File: update_gems.rb

package info (click to toggle)
vagrant 2.2.3%2Bdfsg-1
  • links: PTS, VCS
  • area: main
  • in suites: buster
  • size: 8,072 kB
  • sloc: ruby: 80,731; sh: 369; makefile: 9; lisp: 1
file content (49 lines) | stat: -rw-r--r-- 1,443 bytes parent folder | download | duplicates (6)
1
2
3
4
5
6
7
8
9
10
11
12
13
14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
require "vagrant/plugin/manager"

module VagrantPlugins
  module CommandPlugin
    module Action
      class UpdateGems
        def initialize(app, env)
          @app    = app
        end

        def call(env)
          names = env[:plugin_name] || []

          if names.empty?
            env[:ui].info(I18n.t("vagrant.commands.plugin.updating"))
          else
            env[:ui].info(I18n.t("vagrant.commands.plugin.updating_specific",
                                 names: names.join(", ")))
          end

          manager = Vagrant::Plugin::Manager.instance
          installed_plugins = manager.installed_plugins
          new_specs       = manager.update_plugins(names)
          updated_plugins = manager.installed_plugins

          updated = {}
          installed_plugins.each do |name, info|
            update = updated_plugins[name]
            if update && update["installed_gem_version"] != info["installed_gem_version"]
              updated[name] = update["installed_gem_version"]
            end
          end

          if updated.empty?
            env[:ui].success(I18n.t("vagrant.commands.plugin.up_to_date"))
          end

          updated.each do |name, version|
            env[:ui].success(I18n.t("vagrant.commands.plugin.updated",
                                    name: name, version: version.to_s))
          end

          # Continue
          @app.call(env)
        end
      end
    end
  end
end