Class: Vagrant::Config::V1::Loader

Inherits:
Vagrant::Config::VersionBase show all
Defined in:
lib/vagrant/config/v1/loader.rb

Overview

This is the loader that handles configuration loading for V1 configurations.

Class Method Summary collapse

Methods inherited from Vagrant::Config::VersionBase

upgrade

Class Method Details

.finalize(config) ⇒ Object

Finalizes the configuration by making sure there is at least one VM defined in it.


18
19
20
21
22
23
24
25
# File 'lib/vagrant/config/v1/loader.rb', line 18

def self.finalize(config)
  # Call the `#finalize` method on each of the configuration keys.
  # They're expected to modify themselves in our case.
  config.finalize!

  # Return the object
  config
end

.initV1::Root

Returns a bare empty configuration object.

Returns:


12
13
14
# File 'lib/vagrant/config/v1/loader.rb', line 12

def self.init
  new_root_object
end

.load(config_proc) ⇒ Object

Loads the configuration for the given proc and returns a configuration object.

Parameters:

  • config_proc (Proc)

Returns:

  • (Object)

32
33
34
35
36
37
38
39
40
41
42
# File 'lib/vagrant/config/v1/loader.rb', line 32

def self.load(config_proc)
  # Create a root configuration object
  root = new_root_object

  # Call the proc with the root
  config_proc.call(root)

  # Return the root object, which doubles as the configuration object
  # we actually use for accessing as well.
  root
end

.merge(old, new) ⇒ V1::Root

Merges two configuration objects.

Parameters:

  • old (V1::Root)

    The older root config.

  • new (V1::Root)

    The newer root config.

Returns:


49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
65
66
67
68
69
70
71
72
73
74
75
76
77
78
79
80
81
82
# File 'lib/vagrant/config/v1/loader.rb', line 49

def self.merge(old, new)
  # Grab the internal states, we use these heavily throughout the process
  old_state = old.__internal_state
  new_state = new.__internal_state

  # The config map for the new object is the old one merged with the
  # new one.
  config_map = old_state["config_map"].merge(new_state["config_map"])

  # Merge the keys.
  old_keys = old_state["keys"]
  new_keys = new_state["keys"]
  keys     = {}
  old_keys.each do |key, old_value|
    if new_keys.key?(key)
      # We need to do a merge, which we expect to be available
      # on the config class itself.
      keys[key] = old_value.merge(new_keys[key])
    else
      # We just take the old value, but dup it so that we can modify.
      keys[key] = old_value.dup
    end
  end

  new_keys.each do |key, new_value|
    # Add in the keys that the new class has that we haven't merged.
    if !keys.key?(key)
      keys[key] = new_value.dup
    end
  end

  # Return the final root object
  V1::Root.new(config_map, keys)
end