Class: Vagrant::Box

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant/box.rb

Overview

Represents a "box," which is simply a packaged vagrant environment. Boxes are simply tar files which contain an exported VirtualBox virtual machine, at the least. They are created with vagrant package and may contain additional files if specified by the creator. This class serves to help manage these boxes, although most of the logic is kicked out to middlewares.

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initialize(name, directory, action_runner) ⇒ Box

Creates a new box instance. Given an optional name parameter, newly created instance will have that name, otherwise it defaults to nil.

Note: This method does not actually create the box, but merely returns a new, abstract representation of it. To add a box, see #add.



21
22
23
24
25
# File 'lib/vagrant/box.rb', line 21

def initialize(name, directory, action_runner)
  @name          = name
  @directory     = directory
  @action_runner = action_runner
end

Instance Attribute Details

#directoryObject (readonly)

The directory where this box is stored



13
14
15
# File 'lib/vagrant/box.rb', line 13

def directory
  @directory
end

#nameObject (readonly)

The name of the box.



10
11
12
# File 'lib/vagrant/box.rb', line 10

def name
  @name
end

Instance Method Details

#<=>(other) ⇒ Object

Implemented for comparison with other boxes. Comparison is implemented by simply comparing name.



39
40
41
42
# File 'lib/vagrant/box.rb', line 39

def <=>(other)
  return super if !other.is_a?(self.class)
  name <=> other.name
end

#destroyObject

Begins the process of destroying this box. This cannot be undone!



28
29
30
# File 'lib/vagrant/box.rb', line 28

def destroy
  @action_runner.run(:box_remove, { :box_name => @name, :box_directory => @directory })
end

#repackage(options = nil) ⇒ Object

Begins sequence to repackage this box.



33
34
35
# File 'lib/vagrant/box.rb', line 33

def repackage(options=nil)
  @action_runner.run(:box_repackage, { :box_name => @name, :box_directory => @directory })
end