Environment#home_path is a Pathname object for easier manipulation
This commit is contained in:
parent
86465a36c0
commit
4b17ac0f89
|
@ -5,17 +5,13 @@ module Vagrant
|
||||||
|
|
||||||
attr_accessor :dotfile_name
|
attr_accessor :dotfile_name
|
||||||
attr_accessor :log_output
|
attr_accessor :log_output
|
||||||
attr_writer :home
|
attr_accessor :home
|
||||||
attr_accessor :host
|
attr_accessor :host
|
||||||
|
|
||||||
def initialize
|
def initialize
|
||||||
@home = nil
|
@home = nil
|
||||||
end
|
end
|
||||||
|
|
||||||
def home
|
|
||||||
File.expand_path(@home)
|
|
||||||
end
|
|
||||||
|
|
||||||
def validate(errors)
|
def validate(errors)
|
||||||
[:dotfile_name, :home, :host].each do |field|
|
[:dotfile_name, :home, :host].each do |field|
|
||||||
errors.add("vagrant.config.common.error_empty", :field => field) if !instance_variable_get("@#{field}".to_sym)
|
errors.add("vagrant.config.common.error_empty", :field => field) if !instance_variable_get("@#{field}".to_sym)
|
||||||
|
|
|
@ -58,19 +58,20 @@ module Vagrant
|
||||||
root_path.join(config.vagrant.dotfile_name) rescue nil
|
root_path.join(config.vagrant.dotfile_name) rescue nil
|
||||||
end
|
end
|
||||||
|
|
||||||
# The path to the home directory, which is usually in `~/.vagrant/~
|
# The path to the home directory, expanded relative to the root path,
|
||||||
|
# and converted into a Pathname object.
|
||||||
def home_path
|
def home_path
|
||||||
config ? config.vagrant.home : nil
|
@_home_path ||= Pathname.new(File.expand_path(config.vagrant.home, root_path))
|
||||||
end
|
end
|
||||||
|
|
||||||
# The path to the Vagrant tmp directory
|
# The path to the Vagrant tmp directory
|
||||||
def tmp_path
|
def tmp_path
|
||||||
File.join(home_path, "tmp")
|
home_path.join("tmp")
|
||||||
end
|
end
|
||||||
|
|
||||||
# The path to the Vagrant boxes directory
|
# The path to the Vagrant boxes directory
|
||||||
def boxes_path
|
def boxes_path
|
||||||
File.join(home_path, "boxes")
|
home_path.join("boxes")
|
||||||
end
|
end
|
||||||
|
|
||||||
# Returns the name of the resource which this environment represents.
|
# Returns the name of the resource which this environment represents.
|
||||||
|
@ -260,8 +261,8 @@ module Vagrant
|
||||||
# within the home directory if they're not already created.
|
# within the home directory if they're not already created.
|
||||||
def load_home_directory!
|
def load_home_directory!
|
||||||
# Setup the array of necessary home directories
|
# Setup the array of necessary home directories
|
||||||
dirs = HOME_SUBDIRS.collect { |subdir| File.join(home_path, subdir) }
|
dirs = [home_path]
|
||||||
dirs.unshift(home_path)
|
dirs += HOME_SUBDIRS.collect { |subdir| home_path.join(subdir) }
|
||||||
|
|
||||||
# Go through each required directory, creating it if it doesn't exist
|
# Go through each required directory, creating it if it doesn't exist
|
||||||
dirs.each do |dir|
|
dirs.each do |dir|
|
||||||
|
|
|
@ -5,9 +5,7 @@ class ConfigVagrantTest < Test::Unit::TestCase
|
||||||
@config = Vagrant::Config::VagrantConfig.new
|
@config = Vagrant::Config::VagrantConfig.new
|
||||||
end
|
end
|
||||||
|
|
||||||
should "expand the path if home is not nil" do
|
context "validation" do
|
||||||
@config.home = "foo"
|
# TODO
|
||||||
File.expects(:expand_path).with("foo").once.returns("result")
|
|
||||||
assert_equal "result", @config.home
|
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
|
@ -59,25 +59,21 @@ class EnvironmentTest < Test::Unit::TestCase
|
||||||
end
|
end
|
||||||
|
|
||||||
context "home path" do
|
context "home path" do
|
||||||
should "return nil if config is not yet loaded" do
|
|
||||||
@env.stubs(:config).returns(nil)
|
|
||||||
assert_nil @env.home_path
|
|
||||||
end
|
|
||||||
|
|
||||||
should "return the home path if it loaded" do
|
should "return the home path if it loaded" do
|
||||||
assert_equal @env.config.vagrant.home, @env.home_path
|
expected = Pathname.new(File.expand_path(@env.config.vagrant.home, @env.root_path))
|
||||||
|
assert_equal expected, @env.home_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "temp path" do
|
context "temp path" do
|
||||||
should "return the home path joined with 'tmp'" do
|
should "return the home path joined with 'tmp'" do
|
||||||
assert_equal File.join(@env.home_path, "tmp"), @env.tmp_path
|
assert_equal @env.home_path.join("tmp"), @env.tmp_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
|
||||||
context "boxes path" do
|
context "boxes path" do
|
||||||
should "return the home path joined with 'tmp'" do
|
should "return the home path joined with 'tmp'" do
|
||||||
assert_equal File.join(@env.home_path, "boxes"), @env.boxes_path
|
assert_equal @env.home_path.join("boxes"), @env.boxes_path
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
end
|
end
|
||||||
|
@ -387,7 +383,6 @@ class EnvironmentTest < Test::Unit::TestCase
|
||||||
context "loading home directory" do
|
context "loading home directory" do
|
||||||
setup do
|
setup do
|
||||||
@env = vagrant_env
|
@env = vagrant_env
|
||||||
@home_dir = File.expand_path(@env.config.vagrant.home)
|
|
||||||
|
|
||||||
File.stubs(:directory?).returns(true)
|
File.stubs(:directory?).returns(true)
|
||||||
FileUtils.stubs(:mkdir_p)
|
FileUtils.stubs(:mkdir_p)
|
||||||
|
@ -397,7 +392,7 @@ class EnvironmentTest < Test::Unit::TestCase
|
||||||
create_seq = sequence("create_seq")
|
create_seq = sequence("create_seq")
|
||||||
File.stubs(:directory?).returns(false)
|
File.stubs(:directory?).returns(false)
|
||||||
@klass::HOME_SUBDIRS.each do |subdir|
|
@klass::HOME_SUBDIRS.each do |subdir|
|
||||||
FileUtils.expects(:mkdir_p).with(File.join(@home_dir, subdir)).in_sequence(create_seq)
|
FileUtils.expects(:mkdir_p).with(@env.home_path.join(subdir)).in_sequence(create_seq)
|
||||||
end
|
end
|
||||||
|
|
||||||
@env.load_home_directory!
|
@env.load_home_directory!
|
||||||
|
|
Loading…
Reference in New Issue