Module: Vagrant::Util::StackedProcRunner

Defined in:
lib/vagrant/util/stacked_proc_runner.rb

Overview

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.

Instance Method Summary collapse

Instance Method Details

#proc_stackArray<Proc>

Returns the proc stack. This should always be called as the accessor of the stack. The instance variable itself should never be used.

Returns:

  • (Array<Proc>)


16
17
18
# File 'lib/vagrant/util/stacked_proc_runner.rb', line 16

def proc_stack
  @_proc_stack ||= []
end

#push_proc(&block) ⇒ Object

Adds (pushes) a proc to the stack. The actual proc added here is not executed, but merely stored.

Parameters:

  • block (Proc)


24
25
26
# File 'lib/vagrant/util/stacked_proc_runner.rb', line 24

def push_proc(&block)
  proc_stack << block
end

#run_procs!(*args) ⇒ Object

Executes all the procs on the stack, passing in the given arguments. The stack is not cleared afterwards. It is up to the user of this mixin to clear the stack by calling proc_stack.clear.



31
32
33
34
35
# File 'lib/vagrant/util/stacked_proc_runner.rb', line 31

def run_procs!(*args)
  proc_stack.each do |proc|
    proc.call(*args)
  end
end