diff --git a/lib/vagrant/plugin/v2/components.rb b/lib/vagrant/plugin/v2/components.rb index 7bae6c29a..d7c64d370 100644 --- a/lib/vagrant/plugin/v2/components.rb +++ b/lib/vagrant/plugin/v2/components.rb @@ -54,6 +54,11 @@ module Vagrant # @return [Hash] attr_reader :provider_capabilities + # This contains all the push implementations by name. + # + # @return [Registry>] + attr_reader :pushes + # This contains all the synced folder implementations by name. # # @return [Registry>] @@ -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 diff --git a/lib/vagrant/plugin/v2/plugin.rb b/lib/vagrant/plugin/v2/plugin.rb index 9b09d94b0..bcae23eaa 100644 --- a/lib/vagrant/plugin/v2/plugin.rb +++ b/lib/vagrant/plugin/v2/plugin.rb @@ -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. diff --git a/test/unit/vagrant/plugin/v2/plugin_test.rb b/test/unit/vagrant/plugin/v2/plugin_test.rb index 944d38f9f..442462805 100644 --- a/test/unit/vagrant/plugin/v2/plugin_test.rb +++ b/test/unit/vagrant/plugin/v2/plugin_test.rb @@ -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