Class: HashiCorp::VagrantVMwareDesktop::Action::Checkpoint
- Inherits:
-
Object
- Object
- HashiCorp::VagrantVMwareDesktop::Action::Checkpoint
- Includes:
- Common
- Defined in:
- lib/vagrant-vmware-desktop/action/checkpoint.rb
Overview
This class checks if there is a new release of the Vagrant VMware desktop plugin or the Vagrant VMware utility available and notifies the user
Instance Method Summary collapse
- #alerts_check(env, name, result) ⇒ Object
- #call(env) ⇒ Object
-
#initialize(app, env) ⇒ Checkpoint
constructor
A new instance of Checkpoint.
- #version_check(env, name, result) ⇒ Object
Methods included from Common
Constructor Details
#initialize(app, env) ⇒ Checkpoint
Returns a new instance of Checkpoint.
13 14 15 16 |
# File 'lib/vagrant-vmware-desktop/action/checkpoint.rb', line 13 def initialize(app, env) @app = app @logger = Log4r::Logger.new("hashicorp::provider::vmware::checkpoint") end |
Instance Method Details
#alerts_check(env, name, result) ⇒ Object
35 36 37 38 39 40 41 42 43 44 45 46 47 48 49 50 51 52 53 54 55 56 57 58 59 60 61 62 63 64 65 66 67 68 |
# File 'lib/vagrant-vmware-desktop/action/checkpoint.rb', line 35 def alerts_check(env, name, result) full_name = "vagrant-vmware-#{name}" if result["alerts"] && !result["alerts"].empty? result["alerts"].group_by{|a| a["level"]}.each_pair do |_, alerts| alerts.each do |alert| date = nil begin date = Time.at(alert["date"]) rescue date = Time.now end output = I18n.t("vagrant.hashicorp.vagrant_vmware_desktop.alert", message: alert["message"], date: date, url: alert["url"] ) case alert["level"] when "info" alert_ui = Vagrant::UI::Prefixed.new(env.ui, full_name) alert_ui.info(output) when "warn" alert_ui = Vagrant::UI::Prefixed.new(env.ui, "#{full_name}-warning") alert_ui.warn(output) when "critical" alert_ui = Vagrant::UI::Prefixed.new(env.ui, "#{full_name}-alert") alert_ui.error(output) end end env.ui.info("") end else @logger.debug("no alert notifications to display") end end |
#call(env) ⇒ Object
18 19 20 21 22 23 24 25 26 27 28 29 30 31 32 33 |
# File 'lib/vagrant-vmware-desktop/action/checkpoint.rb', line 18 def call(env) if !env[:checkpoint_complete] if !CheckpointClient.instance.complete? @logger.debug("waiting for checkpoint to complete...") end CheckpointClient.instance.result.each_pair do |name, result| next if !result.is_a?(Hash) next if result["cached"] version_check(env, name, result) alerts_check(env, name, result) end @logger.debug("checkpoint data processing complete") env[:checkpoint_complete] = true end @app.call(env) end |
#version_check(env, name, result) ⇒ Object
70 71 72 73 74 75 76 77 78 79 80 81 82 83 84 85 |
# File 'lib/vagrant-vmware-desktop/action/checkpoint.rb', line 70 def version_check(env, name, result) name = name.to_s latest_version = Gem::Version.new(result["current_version"]) installed_version = Gem::Version.new(result["installed_version"]) ui = Vagrant::UI::Prefixed.new(env.ui, "vagrant-vmware-#{name}") if latest_version > installed_version @logger.info("new version of Vagrant VMware #{name.capitalize} available - #{latest_version}") ui.info(I18n.t("hashicorp.vagrant_vmware_desktop.version_upgrade_available", name: name.capitalize, download_url: download_url["current_download_url"], latest_version: latest_version)) env.ui.info("") else @logger.debug("Vagrant VMware #{name.capitalize} is currently up to date") end end |