Move stacked proc runner to the util directory
This commit is contained in:
parent
d548b451d9
commit
a7652244d5
|
@ -8,7 +8,7 @@ PROJECT_ROOT = File.join(libdir, '..') unless defined?(PROJECT_ROOT)
|
|||
end
|
||||
|
||||
# The vagrant specific files which must be loaded prior to the rest
|
||||
%w{vagrant/util vagrant/stacked_proc_runner vagrant/actions/base vagrant/downloaders/base vagrant/actions/collection
|
||||
%w{vagrant/util vagrant/util/stacked_proc_runner vagrant/actions/base vagrant/downloaders/base vagrant/actions/collection
|
||||
vagrant/actions/runner vagrant/config vagrant/provisioners/base vagrant/provisioners/chef}.each do |f|
|
||||
require File.expand_path(f, libdir)
|
||||
end
|
||||
|
|
|
@ -4,7 +4,7 @@ module Vagrant
|
|||
end
|
||||
|
||||
class Config
|
||||
extend StackedProcRunner
|
||||
extend Util::StackedProcRunner
|
||||
|
||||
@@config = nil
|
||||
|
||||
|
@ -66,7 +66,7 @@ module Vagrant
|
|||
end
|
||||
|
||||
class VMConfig < Base
|
||||
include StackedProcRunner
|
||||
include Util::StackedProcRunner
|
||||
|
||||
attr_accessor :box
|
||||
attr_accessor :box_ovf
|
||||
|
|
|
@ -1,33 +0,0 @@
|
|||
module Vagrant
|
||||
# Represents the "stacked proc runner" behavior which is used a
|
||||
# couple places within Vagrant. This allows procs to "stack" on
|
||||
# each other, then all execute in a single action. An example of
|
||||
# its uses can be seen in the {Config} class.
|
||||
module StackedProcRunner
|
||||
# Returns the proc stack. This should always be called as the
|
||||
# accessor of the stack. The instance variable itself should _never_
|
||||
# be used.
|
||||
#
|
||||
# @return [Array<Proc>]
|
||||
def proc_stack
|
||||
@_proc_stack ||= []
|
||||
end
|
||||
|
||||
# Adds (pushes) a proc to the stack. The actual proc added here is
|
||||
# not executed, but merely stored.
|
||||
#
|
||||
# @param [Proc] block
|
||||
def push_proc(&block)
|
||||
proc_stack << block
|
||||
end
|
||||
|
||||
# Executes all the procs on the stack, passing in the given arguments.
|
||||
# The stack is not cleared afterwords. It is up to the user of this
|
||||
# mixin to clear the stack by calling `proc_stack.clear`.
|
||||
def run_procs!(*args)
|
||||
proc_stack.each do |proc|
|
||||
proc.call(*args)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -0,0 +1,35 @@
|
|||
module Vagrant
|
||||
module Util
|
||||
# Represents the "stacked proc runner" behavior which is used a
|
||||
# couple places within Vagrant. This allows procs to "stack" on
|
||||
# each other, then all execute in a single action. An example of
|
||||
# its uses can be seen in the {Config} class.
|
||||
module StackedProcRunner
|
||||
# Returns the proc stack. This should always be called as the
|
||||
# accessor of the stack. The instance variable itself should _never_
|
||||
# be used.
|
||||
#
|
||||
# @return [Array<Proc>]
|
||||
def proc_stack
|
||||
@_proc_stack ||= []
|
||||
end
|
||||
|
||||
# Adds (pushes) a proc to the stack. The actual proc added here is
|
||||
# not executed, but merely stored.
|
||||
#
|
||||
# @param [Proc] block
|
||||
def push_proc(&block)
|
||||
proc_stack << block
|
||||
end
|
||||
|
||||
# Executes all the procs on the stack, passing in the given arguments.
|
||||
# The stack is not cleared afterwords. It is up to the user of this
|
||||
# mixin to clear the stack by calling `proc_stack.clear`.
|
||||
def run_procs!(*args)
|
||||
proc_stack.each do |proc|
|
||||
proc.call(*args)
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
||||
end
|
|
@ -205,7 +205,7 @@ class ConfigTest < Test::Unit::TestCase
|
|||
end
|
||||
|
||||
should "include the stacked proc runner module" do
|
||||
assert @config.class.included_modules.include?(Vagrant::StackedProcRunner)
|
||||
assert @config.class.included_modules.include?(Vagrant::Util::StackedProcRunner)
|
||||
end
|
||||
|
||||
should "add the customize proc to the proc stack" do
|
||||
|
|
|
@ -1,8 +1,8 @@
|
|||
require File.join(File.dirname(__FILE__), '..', 'test_helper')
|
||||
require File.join(File.dirname(__FILE__), '..', '..', 'test_helper')
|
||||
|
||||
class StackedProcRunnerTest < Test::Unit::TestCase
|
||||
class StackedProcRunnerUtilTest < Test::Unit::TestCase
|
||||
class TestClass
|
||||
include Vagrant::StackedProcRunner
|
||||
include Vagrant::Util::StackedProcRunner
|
||||
end
|
||||
|
||||
setup do
|
Loading…
Reference in New Issue