From 047f9970fe2623fdd7da487029cbfcaf75cbe906 Mon Sep 17 00:00:00 2001 From: Mitchell Hashimoto Date: Wed, 12 Jan 2011 01:02:53 -0800 Subject: [PATCH] Support hash based options for provisioners --- lib/vagrant/config/base.rb | 9 +++++++++ lib/vagrant/config/vm/provisioner.rb | 3 +-- test/vagrant/config/vm/provisioner_test.rb | 5 +++++ 3 files changed, 15 insertions(+), 2 deletions(-) diff --git a/lib/vagrant/config/base.rb b/lib/vagrant/config/base.rb index 2f90ffff6..65a67da52 100644 --- a/lib/vagrant/config/base.rb +++ b/lib/vagrant/config/base.rb @@ -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. diff --git a/lib/vagrant/config/vm/provisioner.rb b/lib/vagrant/config/vm/provisioner.rb index 485ec5e66..8b4343e9a 100644 --- a/lib/vagrant/config/vm/provisioner.rb +++ b/lib/vagrant/config/vm/provisioner.rb @@ -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) diff --git a/test/vagrant/config/vm/provisioner_test.rb b/test/vagrant/config/vm/provisioner_test.rb index 38096ab0a..bf8838fcd 100644 --- a/test/vagrant/config/vm/provisioner_test.rb +++ b/test/vagrant/config/vm/provisioner_test.rb @@ -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