Module: Vagrant::BoxMetadata::Remote

Defined in:
lib/vagrant/box_metadata/remote.rb

Overview

This module enables the BoxMetadata for server mode

Defined Under Namespace

Classes: Version

Instance Attribute Summary collapse

Class Method Summary collapse

Instance Method Summary collapse

Instance Attribute Details

#descriptionObject

Returns the value of attribute description.



18
19
20
# File 'lib/vagrant/box_metadata/remote.rb', line 18

def description
  @description
end

#nameObject

Returns the value of attribute name.



17
18
19
# File 'lib/vagrant/box_metadata/remote.rb', line 17

def name
  @name
end

Class Method Details

.prepended(klass) ⇒ Object

Add an attribute reader for the client when applied to the BoxMetadata class



11
12
13
14
15
# File 'lib/vagrant/box_metadata/remote.rb', line 11

def self.prepended(klass)
  klass.class_eval do
    attr_reader :client
  end
end

Instance Method Details

#initialize(io, url: nil, client: nil) ⇒ Object

Parameters:

  • io (IO)

    An IO object to read the metadata from.



21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
# File 'lib/vagrant/box_metadata/remote.rb', line 21

def initialize(io, url: nil, client: nil)
  @logger = Log4r::Logger.new("vagrant::box")

  if !client.nil? 
    # Use client if available
    @client = client
  else
    # If client is not available, then try to load from url
    if url.nil?
      raise ArgumentError,
        "Metadata URL is required for `#{self.class.name}' if a client is not provided"
    end
    @client = Vagrant.plugin("2").remote_manager.core_plugin_manager.get_plugin("boxmetadata")
    @client.(url)
  end
  @name = @client.name
end

#version(version, **opts) ⇒ Object



39
40
41
42
43
44
45
# File 'lib/vagrant/box_metadata/remote.rb', line 39

def version(version, **opts)
  providers = nil
  providers = Array(opts[:provider]) || []

  v = @client.version(version, providers)
  Version.new(v, ver: v[:version], client: @client)
end

#versions(**opts) ⇒ Object



47
48
49
50
51
52
53
# File 'lib/vagrant/box_metadata/remote.rb', line 47

def versions(**opts)
  provider = nil
  provider = opts[:provider].to_sym if opts[:provider]
  v = @client.list_versions(provider)
  # Sort so the last element of the list is the latest version. 
  v.sort.map(&:to_s)
end