Use a pushes registry instead of data hash

This commit is contained in:
Seth Vargo 2014-10-22 22:29:39 -04:00
parent 0e824cc471
commit 60a8472891
3 changed files with 45 additions and 7 deletions

View File

@ -54,6 +54,11 @@ module Vagrant
# @return [Hash<Symbol, Registry>] # @return [Hash<Symbol, Registry>]
attr_reader :provider_capabilities attr_reader :provider_capabilities
# This contains all the push implementations by name.
#
# @return [Registry<Symbol, Array<Class, Hash>>]
attr_reader :pushes
# This contains all the synced folder implementations by name. # This contains all the synced folder implementations by name.
# #
# @return [Registry<Symbol, Array<Class, Integer>>] # @return [Registry<Symbol, Array<Class, Integer>>]
@ -71,6 +76,7 @@ module Vagrant
@host_capabilities = Hash.new { |h, k| h[k] = Registry.new } @host_capabilities = Hash.new { |h, k| h[k] = Registry.new }
@providers = Registry.new @providers = Registry.new
@provider_capabilities = Hash.new { |h, k| h[k] = Registry.new } @provider_capabilities = Hash.new { |h, k| h[k] = Registry.new }
@pushes = Registry.new
@synced_folders = Registry.new @synced_folders = Registry.new
end end
end end

View File

@ -224,16 +224,13 @@ module Vagrant
# Registers additional pushes to be available. # Registers additional pushes to be available.
# #
# @param [String] name Name of the push. # @param [String] name Name of the push.
# @param [Hash] options List of options for the push.
def self.push(name=UNSET_VALUE, options=nil, &block) def self.push(name=UNSET_VALUE, options=nil, &block)
data[:pushes] ||= Registry.new components.pushes.register(name.to_sym) do
[block.call, options]
# Register a new pusher class only if a name was given
if name != UNSET_VALUE
data[:pushes].register(name.to_sym) { [block.call, options] }
end end
# Return the registry nil
data[:pushes]
end end
# Registers additional synced folder implementations. # Registers additional synced folder implementations.

View File

@ -322,6 +322,41 @@ describe Vagrant::Plugin::V2::Plugin do
end end
end end
describe "pushes" do
it "should register implementations" do
plugin = Class.new(described_class) do
push("foo") { "bar" }
end
expect(plugin.components.pushes[:foo]).to eq(["bar", nil])
end
it "should be able to specify priorities" do
plugin = Class.new(described_class) do
push("foo", bar: 1) { "bar" }
end
expect(plugin.components.pushes[:foo]).to eq(["bar", bar: 1])
end
it "should lazily register implementations" 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
push("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.components.pushes[:foo]
}.to raise_error(StandardError)
end
end
describe "synced folders" do describe "synced folders" do
it "should register implementations" do it "should register implementations" do
plugin = Class.new(described_class) do plugin = Class.new(described_class) do