class HashiCorp::VagrantVMwareDesktop::Action::Checkpoint
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
Public Class Methods
new(app, env)
click to toggle source
# File lib/vagrant-vmware-desktop/action/checkpoint.rb, line 10 def initialize(app, env) @app = app @logger = Log4r::Logger.new("hashicorp::provider::vmware::checkpoint") end
Public Instance Methods
alerts_check(env, name, result)
click to toggle source
# File lib/vagrant-vmware-desktop/action/checkpoint.rb, line 32 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)
click to toggle source
# File lib/vagrant-vmware-desktop/action/checkpoint.rb, line 15 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)
click to toggle source
# File lib/vagrant-vmware-desktop/action/checkpoint.rb, line 67 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