From 761da0de631066573f5c4b6632aebc6e5c27f5e6 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Sat, 11 Sep 2010 10:21:35 -0700 Subject: [PATCH] Remove method calls to "Box.find" and remove method --- lib/vagrant/action/vm/check_box.rb | 2 +- lib/vagrant/box.rb | 46 ------------------------ lib/vagrant/command/box.rb | 4 +-- test/vagrant/action/vm/check_box_test.rb | 5 ++- test/vagrant/box_test.rb | 27 -------------- 5 files changed, 5 insertions(+), 79 deletions(-) diff --git a/lib/vagrant/action/vm/check_box.rb b/lib/vagrant/action/vm/check_box.rb index 6d2318505..1e4a8abc0 100644 --- a/lib/vagrant/action/vm/check_box.rb +++ b/lib/vagrant/action/vm/check_box.rb @@ -10,7 +10,7 @@ module Vagrant box_name = env["config"].vm.box 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 raise Errors::BoxSpecifiedDoesntExist.new(:name => box_name) if !box_url diff --git a/lib/vagrant/box.rb b/lib/vagrant/box.rb index 9035a2874..37acdad39 100644 --- a/lib/vagrant/box.rb +++ b/lib/vagrant/box.rb @@ -5,41 +5,6 @@ module Vagrant # 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 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 # The name of the box. attr_accessor :name @@ -69,17 +34,6 @@ module Vagrant results 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 # begins the process of adding a box from a given URI by setting up # the {Box} instance and calling {#add}. diff --git a/lib/vagrant/command/box.rb b/lib/vagrant/command/box.rb index bed72fc39..76f77320b 100644 --- a/lib/vagrant/command/box.rb +++ b/lib/vagrant/command/box.rb @@ -10,14 +10,14 @@ module Vagrant desc "remove NAME", "Remove a box from the system" def remove(name) - b = Box.find(env, name) + b = env.boxes.find(env, name) raise BoxNotFound.new(:name => name) if !b b.destroy end desc "repackage NAME", "Repackage an installed box into a `.box` file." def repackage(name) - b = Box.find(env, name) + b = env.boxes.find(env, name) raise BoxNotFound.new(:name => name) if !b b.repackage end diff --git a/test/vagrant/action/vm/check_box_test.rb b/test/vagrant/action/vm/check_box_test.rb index 1c258ae9a..c8dea75d4 100644 --- a/test/vagrant/action/vm/check_box_test.rb +++ b/test/vagrant/action/vm/check_box_test.rb @@ -7,7 +7,6 @@ class CheckBoxVMActionTest < Test::Unit::TestCase context "calling" do setup do - Vagrant::Box.stubs(:find) end should "raise error if box not specified" do @@ -31,7 +30,7 @@ class CheckBoxVMActionTest < Test::Unit::TestCase instance = @klass.new(app, env) 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) { instance.call(env) @@ -46,7 +45,7 @@ class CheckBoxVMActionTest < Test::Unit::TestCase instance = @klass.new(app, env) 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) env.env.expects(:load_box!).in_sequence(seq) app.expects(:call).with(env).once.in_sequence(seq) diff --git a/test/vagrant/box_test.rb b/test/vagrant/box_test.rb index 4e457cf07..c2ddaa74f 100644 --- a/test/vagrant/box_test.rb +++ b/test/vagrant/box_test.rb @@ -53,33 +53,6 @@ class BoxTest < Test::Unit::TestCase 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 setup do @name = "foo"