Use a pushes registry instead of data hash
This commit is contained in:
parent
0e824cc471
commit
60a8472891
|
@ -54,6 +54,11 @@ module Vagrant
|
|||
# @return [Hash<Symbol, Registry>]
|
||||
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.
|
||||
#
|
||||
# @return [Registry<Symbol, Array<Class, Integer>>]
|
||||
|
@ -71,6 +76,7 @@ module Vagrant
|
|||
@host_capabilities = Hash.new { |h, k| h[k] = Registry.new }
|
||||
@providers = Registry.new
|
||||
@provider_capabilities = Hash.new { |h, k| h[k] = Registry.new }
|
||||
@pushes = Registry.new
|
||||
@synced_folders = Registry.new
|
||||
end
|
||||
end
|
||||
|
|
|
@ -224,16 +224,13 @@ module Vagrant
|
|||
# Registers additional pushes to be available.
|
||||
#
|
||||
# @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)
|
||||
data[:pushes] ||= Registry.new
|
||||
|
||||
# Register a new pusher class only if a name was given
|
||||
if name != UNSET_VALUE
|
||||
data[:pushes].register(name.to_sym) { [block.call, options] }
|
||||
components.pushes.register(name.to_sym) do
|
||||
[block.call, options]
|
||||
end
|
||||
|
||||
# Return the registry
|
||||
data[:pushes]
|
||||
nil
|
||||
end
|
||||
|
||||
# Registers additional synced folder implementations.
|
||||
|
|
|
@ -322,6 +322,41 @@ describe Vagrant::Plugin::V2::Plugin do
|
|||
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
|
||||
it "should register implementations" do
|
||||
plugin = Class.new(described_class) do
|
||||
|
|
Loading…
Reference in New Issue