diff --git a/lib/vagrant/plugin/v2/components.rb b/lib/vagrant/plugin/v2/components.rb index 2301656da..a9a7e50f7 100644 --- a/lib/vagrant/plugin/v2/components.rb +++ b/lib/vagrant/plugin/v2/components.rb @@ -6,12 +6,19 @@ module Vagrant # components, and the actual container of those components. This # removes a bit of state overhead from the plugin class itself. class Components + # This contains all the action hooks. + # + # @return [Array] + attr_reader :action_hooks + # This contains all the configuration plugins by scope. # # @return [Hash] attr_reader :configs def initialize + @action_hooks = [] + # Create the configs hash which defaults to a registry @configs = Hash.new { |h, k| h[k] = Registry.new } end diff --git a/lib/vagrant/plugin/v2/plugin.rb b/lib/vagrant/plugin/v2/plugin.rb index ff5c38100..2246895dc 100644 --- a/lib/vagrant/plugin/v2/plugin.rb +++ b/lib/vagrant/plugin/v2/plugin.rb @@ -65,18 +65,12 @@ module Vagrant # is run. This allows plugin authors to hook into things like VM # bootup, VM provisioning, etc. # - # @param [Symbol] name Name of the action. + # @param [String] name Name of the action. # @return [Array] List of the hooks for the given action. def self.action_hook(name, &block) - # Get the list of hooks for the given hook name - data[:action_hooks] ||= {} - hooks = data[:action_hooks][name.to_sym] ||= [] + # The name is currently not used but we want it for the future. - # Return the list if we don't have a block - return hooks if !block_given? - - # Otherwise add the block to the list of hooks for this action. - hooks << block + components.action_hooks << block end # Defines additional command line commands available by key. The key diff --git a/test/unit/vagrant/plugin/v2/plugin_test.rb b/test/unit/vagrant/plugin/v2/plugin_test.rb index b2bd24487..935936920 100644 --- a/test/unit/vagrant/plugin/v2/plugin_test.rb +++ b/test/unit/vagrant/plugin/v2/plugin_test.rb @@ -29,7 +29,7 @@ describe Vagrant::Plugin::V2::Plugin do action_hook("foo") { "bar" } end - hooks = plugin.action_hook("foo") + hooks = plugin.components.action_hooks hooks.length.should == 1 hooks[0].call.should == "bar" end