Remove method calls to "Box.find" and remove method
This commit is contained in:
parent
0ee21998f6
commit
761da0de63
|
@ -10,7 +10,7 @@ module Vagrant
|
||||||
box_name = env["config"].vm.box
|
box_name = env["config"].vm.box
|
||||||
raise Errors::BoxNotSpecified.new if !box_name
|
raise Errors::BoxNotSpecified.new if !box_name
|
||||||
|
|
||||||
if !Vagrant::Box.find(env.env , box_name)
|
if !env.env.boxes.find(box_name)
|
||||||
box_url = env["config"].vm.box_url
|
box_url = env["config"].vm.box_url
|
||||||
raise Errors::BoxSpecifiedDoesntExist.new(:name => box_name) if !box_url
|
raise Errors::BoxSpecifiedDoesntExist.new(:name => box_name) if !box_url
|
||||||
|
|
||||||
|
|
|
@ -5,41 +5,6 @@ module Vagrant
|
||||||
# and may contain additional files if specified by the creator. This
|
# and may contain additional files if specified by the creator. This
|
||||||
# class serves to help manage these boxes, although most of the logic
|
# class serves to help manage these boxes, although most of the logic
|
||||||
# is kicked out to actions.
|
# is kicked out to actions.
|
||||||
#
|
|
||||||
# What can the {Box} class do?
|
|
||||||
#
|
|
||||||
# * Find boxes
|
|
||||||
# * Add existing boxes (from some URI)
|
|
||||||
# * Delete existing boxes
|
|
||||||
#
|
|
||||||
# # Finding Boxes
|
|
||||||
#
|
|
||||||
# Using the {Box.find} method, you can search for existing boxes. This
|
|
||||||
# method will return `nil` if none is found or an instance of {Box}
|
|
||||||
# otherwise.
|
|
||||||
#
|
|
||||||
# box = Vagrant::Box.find("base")
|
|
||||||
# if box.nil?
|
|
||||||
# puts "Box not found!"
|
|
||||||
# else
|
|
||||||
# puts "Box exists at #{box.directory}"
|
|
||||||
# end
|
|
||||||
#
|
|
||||||
# # Adding a Box
|
|
||||||
#
|
|
||||||
# Boxes can be added from any URI. Some schemas aren't supported; if this
|
|
||||||
# is the case, the error will output to the logger.
|
|
||||||
#
|
|
||||||
# Vagrant::Box.add("foo", "http://myfiles.com/foo.box")
|
|
||||||
#
|
|
||||||
# # Destroying a box
|
|
||||||
#
|
|
||||||
# Boxes can be deleted as well. This method is _final_ and there is no way
|
|
||||||
# to undo this action once it is completed.
|
|
||||||
#
|
|
||||||
# box = Vagrant::Box.find("foo")
|
|
||||||
# box.destroy
|
|
||||||
#
|
|
||||||
class Box
|
class Box
|
||||||
# The name of the box.
|
# The name of the box.
|
||||||
attr_accessor :name
|
attr_accessor :name
|
||||||
|
@ -69,17 +34,6 @@ module Vagrant
|
||||||
results
|
results
|
||||||
end
|
end
|
||||||
|
|
||||||
# Finds a box with the given name. This method searches for a box
|
|
||||||
# with the given name, returning `nil` if none is found or returning
|
|
||||||
# a {Box} instance otherwise.
|
|
||||||
#
|
|
||||||
# @param [String] name The name of the box
|
|
||||||
# @return [Box] Instance of {Box} representing the box found
|
|
||||||
def find(env, name)
|
|
||||||
return nil unless File.directory?(directory(env, name))
|
|
||||||
new(env, name)
|
|
||||||
end
|
|
||||||
|
|
||||||
# Adds a new box with given name from the given URI. This method
|
# 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
|
# begins the process of adding a box from a given URI by setting up
|
||||||
# the {Box} instance and calling {#add}.
|
# the {Box} instance and calling {#add}.
|
||||||
|
|
|
@ -10,14 +10,14 @@ module Vagrant
|
||||||
|
|
||||||
desc "remove NAME", "Remove a box from the system"
|
desc "remove NAME", "Remove a box from the system"
|
||||||
def remove(name)
|
def remove(name)
|
||||||
b = Box.find(env, name)
|
b = env.boxes.find(env, name)
|
||||||
raise BoxNotFound.new(:name => name) if !b
|
raise BoxNotFound.new(:name => name) if !b
|
||||||
b.destroy
|
b.destroy
|
||||||
end
|
end
|
||||||
|
|
||||||
desc "repackage NAME", "Repackage an installed box into a `.box` file."
|
desc "repackage NAME", "Repackage an installed box into a `.box` file."
|
||||||
def repackage(name)
|
def repackage(name)
|
||||||
b = Box.find(env, name)
|
b = env.boxes.find(env, name)
|
||||||
raise BoxNotFound.new(:name => name) if !b
|
raise BoxNotFound.new(:name => name) if !b
|
||||||
b.repackage
|
b.repackage
|
||||||
end
|
end
|
||||||
|
|
|
@ -7,7 +7,6 @@ class CheckBoxVMActionTest < Test::Unit::TestCase
|
||||||
|
|
||||||
context "calling" do
|
context "calling" do
|
||||||
setup do
|
setup do
|
||||||
Vagrant::Box.stubs(:find)
|
|
||||||
end
|
end
|
||||||
|
|
||||||
should "raise error if box not specified" do
|
should "raise error if box not specified" do
|
||||||
|
@ -31,7 +30,7 @@ class CheckBoxVMActionTest < Test::Unit::TestCase
|
||||||
|
|
||||||
instance = @klass.new(app, env)
|
instance = @klass.new(app, env)
|
||||||
app.expects(:call).never
|
app.expects(:call).never
|
||||||
Vagrant::Box.expects(:find).with(env.env, env["config"].vm.box).returns(nil)
|
env.env.boxes.expects(:find).with(env["config"].vm.box).returns(nil)
|
||||||
|
|
||||||
assert_raises(Vagrant::Errors::BoxSpecifiedDoesntExist) {
|
assert_raises(Vagrant::Errors::BoxSpecifiedDoesntExist) {
|
||||||
instance.call(env)
|
instance.call(env)
|
||||||
|
@ -46,7 +45,7 @@ class CheckBoxVMActionTest < Test::Unit::TestCase
|
||||||
|
|
||||||
instance = @klass.new(app, env)
|
instance = @klass.new(app, env)
|
||||||
seq = sequence("seq")
|
seq = sequence("seq")
|
||||||
Vagrant::Box.expects(:find).returns(nil)
|
env.env.boxes.expects(:find).returns(nil)
|
||||||
Vagrant::Box.expects(:add).with(env.env, env["config"].vm.box, env["config"].vm.box_url).in_sequence(seq)
|
Vagrant::Box.expects(:add).with(env.env, env["config"].vm.box, env["config"].vm.box_url).in_sequence(seq)
|
||||||
env.env.expects(:load_box!).in_sequence(seq)
|
env.env.expects(:load_box!).in_sequence(seq)
|
||||||
app.expects(:call).with(env).once.in_sequence(seq)
|
app.expects(:call).with(env).once.in_sequence(seq)
|
||||||
|
|
|
@ -53,33 +53,6 @@ class BoxTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "finding" do
|
|
||||||
setup do
|
|
||||||
@dir = "foo"
|
|
||||||
@name = "bar"
|
|
||||||
Vagrant::Box.stubs(:directory).with(@env, @name).returns(@dir)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "return nil if the box doesn't exist" do
|
|
||||||
File.expects(:directory?).with(@dir).once.returns(false)
|
|
||||||
assert_nil Vagrant::Box.find(@env, @name)
|
|
||||||
end
|
|
||||||
|
|
||||||
should "return a box object with the proper name set" do
|
|
||||||
File.expects(:directory?).with(@dir).once.returns(true)
|
|
||||||
result = Vagrant::Box.find(@env, @name)
|
|
||||||
assert result
|
|
||||||
assert_equal @name, result.name
|
|
||||||
end
|
|
||||||
|
|
||||||
should "return a box object with the proper env set" do
|
|
||||||
File.expects(:directory?).with(@dir).once.returns(true)
|
|
||||||
result = Vagrant::Box.find(@env, @name)
|
|
||||||
assert result
|
|
||||||
assert_equal @env, result.env
|
|
||||||
end
|
|
||||||
end
|
|
||||||
|
|
||||||
context "adding" do
|
context "adding" do
|
||||||
setup do
|
setup do
|
||||||
@name = "foo"
|
@name = "foo"
|
||||||
|
|
Loading…
Reference in New Issue