Remove box dependence on env

This commit is contained in:
Mitchell Hashimoto 2011-12-04 14:06:05 -08:00
parent 8801bc7b1b
commit 833dbf8fc4
2 changed files with 7 additions and 41 deletions

View File

@ -12,24 +12,8 @@ module Vagrant
# The URI for a new box. This is not available for existing boxes. # The URI for a new box. This is not available for existing boxes.
attr_accessor :uri attr_accessor :uri
# The environment which this box belongs to. Although this could # The directory where this box is stored
# actually be many environments, this points to the environment attr_reader :directory
# of a specific instance.
attr_reader :env
class << self
# Adds a new box with given name from the given URI. This method
# begins the process of adding a box from a given URI by setting up
# the {Box} instance and calling {#add}.
#
# @param [String] name The name of the box
# @param [String] uri URI to the box file
def add(env, name, uri)
box = new(env, name)
box.uri = uri
box.add
end
end
# Creates a new box instance. Given an optional `name` parameter, # Creates a new box instance. Given an optional `name` parameter,
# newly created instance will have that name, otherwise it defaults # newly created instance will have that name, otherwise it defaults
@ -37,9 +21,9 @@ module Vagrant
# #
# **Note:** This method does not actually _create_ the box, but merely # **Note:** This method does not actually _create_ the box, but merely
# returns a new, abstract representation of it. To add a box, see {#add}. # returns a new, abstract representation of it. To add a box, see {#add}.
def initialize(env=nil, name=nil) def initialize(name, directory)
@name = name @name = name
@env = env @directory = directory
end end
# Returns path to the OVF file of the box. The OVF file is an open # Returns path to the OVF file of the box. The OVF file is an open
@ -71,15 +55,6 @@ module Vagrant
env.actions.run(:box_repackage, { "box" => self, "validate" => false }.merge(options || {})) env.actions.run(:box_repackage, { "box" => self, "validate" => false }.merge(options || {}))
end end
# Returns the directory to the location of this boxes content in the local
# filesystem. Note that if the box isn't imported yet, then the path may not
# yet exist, but still represents where the box will be imported to.
#
# @return [String]
def directory
env.boxes_path.join(name)
end
# Implemented for comparison with other boxes. Comparison is implemented # Implemented for comparison with other boxes. Comparison is implemented
# by simply comparing name. # by simply comparing name.
def <=>(other) def <=>(other)

View File

@ -2,15 +2,7 @@ require 'forwardable'
module Vagrant module Vagrant
# Represents a collection of boxes, providing helpful methods for # Represents a collection of boxes, providing helpful methods for
# finding boxes. An instance of this is returned by {Environment#boxes}. # finding boxes.
#
# # Finding a Box
#
# To find a box, use the {#find} method with the name of the box. The name
# is an exact match search.
#
# env.boxes.find("base") # => #<Vagrant::Box>
#
class BoxCollection class BoxCollection
include Enumerable include Enumerable
extend Forwardable extend Forwardable
@ -45,8 +37,7 @@ module Vagrant
Dir.open(@directory) do |dir| Dir.open(@directory) do |dir|
dir.each do |d| dir.each do |d|
next if d == "." || d == ".." || !@directory.join(d).directory? next if d == "." || d == ".." || !@directory.join(d).directory?
# TODO: env???? @boxes << Box.new(d, @directory.join(d))
@boxes << Box.new(env, d)
end end
end end
end end