Module: VagrantBoxVersion::VersionChecking

Included in:
Action::Check, Command
Defined in:
lib/vagrant_box_version/version-checking.rb

Instance Method Summary collapse

Instance Method Details

#check(machine, ui) ⇒ Object



29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/vagrant_box_version/version-checking.rb', line 29

def check(machine, ui)
  box = machine.box
  unless box.nil?
    version = local_version(box.directory)
    remote = remote_version(machine.config.version.url, box.name)

    ui.info("Local version is #{version || "unknown"}", scope: machine.name)

    if (version || VersionString.new("0")) < (remote || VersionString.new("0"))
      ui.warn("Version #{remote} is available!", scope: machine.name)
      ui.info("To update, run:")
      ui.info("  vagrant destroy #{machine.name} && vagrant box remove #{box.name} #{box.provider.to_s}")
    elsif version.nil?
      ui.warn("Local version couldn't be determined. You should probably upgrade your box.", scope: machine.name)
    elsif remote.nil?
      ui.warn("Remote version couldn't be determined. Try again later.", scope: machine.name)
    else
      ui.success("You are up to date!", scope: machine.name)
    end
  else
    ui.success("There is no local box yet. Nothing to do.", scope: machine.name)
  end
end

#local_version(boxdir) ⇒ Object



53
54
55
56
# File 'lib/vagrant_box_version/version-checking.rb', line 53

def local_version(boxdir)
  versionfile = File.join(boxdir, "include", "version")
  if File.exists? versionfile then VersionString.new(File.read(versionfile)) else nil end
end

#remote_version(server, name) ⇒ Object



58
59
60
61
62
63
64
# File 'lib/vagrant_box_version/version-checking.rb', line 58

def remote_version(server, name)
  begin
    VersionString.new(open("#{server}/#{name}.box.version").read)
  rescue
    nil
  end
end