Support hash based options for provisioners

This commit is contained in:
Mitchell Hashimoto 2011-01-12 01:02:53 -08:00
parent 4e5a7aa6bf
commit 047f9970fe
3 changed files with 15 additions and 2 deletions

View File

@ -32,6 +32,15 @@ module Vagrant
end
end
# Allows setting options from a hash. By default this simply calls
# the `#{key}=` method on the config class with the value, which is
# the expected behavior most of the time.
def set_options(options)
options.each do |key, value|
send("#{key}=", value)
end
end
# Called by {Top} after the configuration is loaded to validate
# the configuaration objects. Subclasses should implement this
# method and add any errors to the `errors` object given.

View File

@ -29,9 +29,8 @@ module Vagrant
# Instantiate the config class and configure it
@config = @provisioner.const_get(*const_args).new
@config.set_options(options) if options
block.call(@config) if block
# TODO: Deal with the options hash
end
def validate(errors)

View File

@ -38,6 +38,11 @@ class ConfigVMProvisionerTest < Test::Unit::TestCase
assert_equal "foo", instance.config.cookbooks_path
end
should "configure the provisioner with a hash if valid" do
instance = @klass.new(:chef_solo, :cookbooks_path => "foo")
assert_equal "foo", instance.config.cookbooks_path
end
end
context "validation" do