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.



21
22
23
24
25
26
27
28
# File 'lib/vagrant/config/v1/loader.rb', line 21

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:



15
16
17
# File 'lib/vagrant/config/v1/loader.rb', line 15

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)


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

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:



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
83
84
85
# File 'lib/vagrant/config/v1/loader.rb', line 52

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