Module: Vagrant::Config

Defined in:
lib/vagrant/config.rb,
lib/vagrant/config/vm.rb,
lib/vagrant/config/nfs.rb,
lib/vagrant/config/ssh.rb,
lib/vagrant/config/top.rb,
lib/vagrant/config/base.rb,
lib/vagrant/config/loader.rb,
lib/vagrant/config/package.rb,
lib/vagrant/config/vagrant.rb,
lib/vagrant/config/container.rb,
lib/vagrant/config/vm/sub_vm.rb,
lib/vagrant/config/error_recorder.rb,
lib/vagrant/config/vm/provisioner.rb

Defined Under Namespace

Classes: Base, Container, ErrorRecorder, Loader, NFSConfig, PackageConfig, SSHConfig, Top, VMConfig, VagrantConfig

Constant Summary collapse

CONFIGURE_MUTEX =
Mutex.new

Class Method Summary collapse

Class Method Details

.capture_configuresObject

This is a method which will yield to a block and will capture all Vagrant.configure calls, returning an array of Procs.

Wrapping this around anytime you call code which loads configurations will force a mutex so that procs never get mixed up. This keeps the configuration loading part of Vagrant thread-safe.



35
36
37
38
39
40
41
42
43
44
45
46
47
# File 'lib/vagrant/config.rb', line 35

def self.capture_configures
  CONFIGURE_MUTEX.synchronize do
    # Reset the last procs so that we start fresh
    @last_procs = []

    # Yield to allow the caller to do whatever loading needed
    yield

    # Return the last procs we've seen while still in the mutex,
    # knowing we're safe.
    return @last_procs
  end
end

.run(&block) ⇒ Object

This is the method which is called by all Vagrantfiles to configure Vagrant. This method expects a block which accepts a single argument representing an instance of the Top class.

Note that the block is not run immediately. Instead, it's proc is stored away for execution later.



23
24
25
26
27
# File 'lib/vagrant/config.rb', line 23

def self.run(&block)
  # Store it for later
  @last_procs ||= []
  @last_procs << block
end