Machine objects are passed into validate instead of env

This commit is contained in:
Mitchell Hashimoto 2013-01-18 12:42:49 -08:00
parent 3e9e422ce0
commit 3f3c7027aa
3 changed files with 8 additions and 9 deletions

View File

@ -45,14 +45,14 @@ module Vagrant
# #
# @param [Environment] env # @param [Environment] env
# @return [Hash] # @return [Hash]
def validate(env) def validate(machine)
# Go through each of the configuration keys and validate # Go through each of the configuration keys and validate
errors = {} errors = {}
@keys.each do |_key, instance| @keys.each do |_key, instance|
if instance.respond_to?(:validate) if instance.respond_to?(:validate)
# Validate this single item, and if we have errors then # Validate this single item, and if we have errors then
# we merge them into our total errors list. # we merge them into our total errors list.
result = instance.validate(env) result = instance.validate(machine)
if result && !result.empty? if result && !result.empty?
result.each do |key, value| result.each do |key, value|
if !value.empty? if !value.empty?

View File

@ -15,7 +15,7 @@ module VagrantPlugins
attr_accessor :forward_x11 attr_accessor :forward_x11
attr_accessor :shell attr_accessor :shell
def validate(env) def validate(machine)
errors = [] errors = []
[:username, :max_tries, :timeout].each do |field| [:username, :max_tries, :timeout].each do |field|
@ -23,7 +23,8 @@ module VagrantPlugins
errors << I18n.t("vagrant.config.common.error_empty", :field => field) if !value errors << I18n.t("vagrant.config.common.error_empty", :field => field) if !value
end end
if private_key_path && !File.file?(File.expand_path(private_key_path, env.root_path)) if private_key_path && \
!File.file?(File.expand_path(private_key_path, machine.env.root_path))
errors << I18n.t("vagrant.config.ssh.private_key_missing", :path => private_key_path) errors << I18n.t("vagrant.config.ssh.private_key_missing", :path => private_key_path)
end end

View File

@ -122,16 +122,14 @@ module VagrantPlugins
define(DEFAULT_VM_NAME) if defined_vm_keys.empty? define(DEFAULT_VM_NAME) if defined_vm_keys.empty?
end end
def validate(env) def validate(machine)
errors = [] errors = []
errors << I18n.t("vagrant.config.vm.box_missing") if !box errors << I18n.t("vagrant.config.vm.box_missing") if !box
errors << I18n.t("vagrant.config.vm.box_not_found", :name => box) if \ errors << I18n.t("vagrant.config.vm.box_not_found", :name => box) if \
box && !box_url && !env.boxes.find(box, :virtualbox) box && !box_url && !machine.box
errors << I18n.t("vagrant.config.vm.base_mac_invalid") if \
env.boxes.find(box, :virtualbox) && !base_mac
shared_folders.each do |name, options| shared_folders.each do |name, options|
hostpath = Pathname.new(options[:hostpath]).expand_path(env.root_path) hostpath = Pathname.new(options[:hostpath]).expand_path(machine.env.root_path)
if !hostpath.directory? && !options[:create] if !hostpath.directory? && !options[:create]
errors << I18n.t("vagrant.config.vm.shared_folder_hostpath_missing", errors << I18n.t("vagrant.config.vm.shared_folder_hostpath_missing",