diff --git a/lib/vagrant/plugin/v1/plugin.rb b/lib/vagrant/plugin/v1/plugin.rb index decc7aaae..abb503549 100644 --- a/lib/vagrant/plugin/v1/plugin.rb +++ b/lib/vagrant/plugin/v1/plugin.rb @@ -181,6 +181,19 @@ module Vagrant data[:hosts] end + # Registers additional providers to be available. + # + # @param [Symbol] name Name of the provider. + def self.provider(name=UNSET_VALUE, &block) + data[:providers] ||= Registry.new + + # Register a new provider class only if a name was given + data[:providers].register(name.to_sym, &block) if name != UNSET_VALUE + + # Return the registry + data[:providers] + end + # Registers additional provisioners to be available. # # @param [String] name Name of the provisioner. diff --git a/plugins/providers/virtualbox/plugin.rb b/plugins/providers/virtualbox/plugin.rb new file mode 100644 index 000000000..487bc4ec8 --- /dev/null +++ b/plugins/providers/virtualbox/plugin.rb @@ -0,0 +1,18 @@ +require "vagrant" + +module VagrantPlugins + module ProviderVirtualBox + class Plugin < Vagrant.plugin("1") + name "virtualbox provider" + description <<-EOF + The VirtualBox provider allows Vagrant to manage and control + VirtualBox-based virtual machines. + EOF + + provider("virtualbox") do + require File.expand_path("../provider", __FILE__) + Provider + end + end + end +end diff --git a/plugins/providers/virtualbox/provider.rb b/plugins/providers/virtualbox/provider.rb new file mode 100644 index 000000000..8cbd51f74 --- /dev/null +++ b/plugins/providers/virtualbox/provider.rb @@ -0,0 +1,6 @@ +module VagrantPlugins + module ProviderVirtualBox + class Provider < Vagrant.plugin("1", :provider) + end + end +end diff --git a/test/unit/vagrant/plugin/v1/plugin_test.rb b/test/unit/vagrant/plugin/v1/plugin_test.rb index e79f75b9a..6a20f14b8 100644 --- a/test/unit/vagrant/plugin/v1/plugin_test.rb +++ b/test/unit/vagrant/plugin/v1/plugin_test.rb @@ -195,6 +195,34 @@ describe Vagrant::Plugin::V1::Plugin do end end + describe "providers" do + it "should register provider classes" do + plugin = Class.new(described_class) do + provider("foo") { "bar" } + end + + plugin.provider[:foo].should == "bar" + end + + it "should lazily register provider classes" do + # Below would raise an error if the value of the config class was + # evaluated immediately. By asserting that this does not raise an + # error, we verify that the value is actually lazily loaded + plugin = nil + expect { + plugin = Class.new(described_class) do + provider("foo") { raise StandardError, "FAIL!" } + end + }.to_not raise_error + + # Now verify when we actually get the configuration key that + # a proper error is raised. + expect { + plugin.provider[:foo] + }.to raise_error(StandardError) + end + end + describe "provisioners" do it "should register provisioner classes" do plugin = Class.new(described_class) do