Add the "provider" API to the V1 plugin.
This commit is contained in:
parent
436da57cc4
commit
3519bf0372
|
@ -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.
|
||||
|
|
|
@ -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
|
|
@ -0,0 +1,6 @@
|
|||
module VagrantPlugins
|
||||
module ProviderVirtualBox
|
||||
class Provider < Vagrant.plugin("1", :provider)
|
||||
end
|
||||
end
|
||||
end
|
|
@ -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
|
||||
|
|
Loading…
Reference in New Issue