Sha256: 8c5c839cb89d1a9ef484df39c2fb4c2f975791af71bd4849295614632620a159

Contents?: true

Size: 1.97 KB

Versions: 20

Compression:

Stored size: 1.97 KB

Contents

require "set"

module Vagrant
  module Config
    module V1
      # This is the root configuration class. An instance of this is what
      # is passed into version 1 Vagrant configuration blocks.
      class Root
        # Initializes a root object that maps the given keys to specific
        # configuration classes.
        #
        # @param [Hash] config_map Map of key to config class.
        def initialize(config_map, keys=nil)
          @keys              = keys || {}
          @config_map        = config_map
          @missing_key_calls = Set.new
        end

        # We use method_missing as a way to get the configuration that is
        # used for Vagrant and load the proper configuration classes for
        # each.
        def method_missing(name, *args)
          return @keys[name] if @keys.has_key?(name)

          config_klass = @config_map[name.to_sym]
          if config_klass
            # Instantiate the class and return the instance
            @keys[name] = config_klass.new
            return @keys[name]
          else
            # Record access to a missing key as an error
            @missing_key_calls.add(name.to_s)
            return DummyConfig.new
          end
        end

        # Called to finalize this object just prior to it being used by
        # the Vagrant system. The "!" signifies that this is expected to
        # mutate itself.
        def finalize!
          @keys.each do |_key, instance|
            instance.finalize!
          end
        end

        # Returns the internal state of the root object. This is used
        # by outside classes when merging, and shouldn't be called directly.
        # Note the strange method name is to attempt to avoid any name
        # clashes with potential configuration keys.
        def __internal_state
          {
            "config_map"        => @config_map,
            "keys"              => @keys,
            "missing_key_calls" => @missing_key_calls
          }
        end
      end
    end
  end
end

Version data entries

20 entries across 20 versions & 7 rubygems

Version Path
tamtam-vagrant-reload-1.1.3 vendor/cache/vagrant-0ac2a8738841/lib/vagrant/config/v1/root.rb
tamtam-vagrant-reload-1.1.2 vendor/cache/vagrant-0ac2a8738841/lib/vagrant/config/v1/root.rb
tamtam-vagrant-reload-1.1.1 vendor/cache/vagrant-0ac2a8738841/lib/vagrant/config/v1/root.rb
tamtam-vagrant-reload-1.1 vendor/cache/vagrant-0ac2a8738841/lib/vagrant/config/v1/root.rb
vagrant-tiktalik-0.0.3 vendor/bundle/ruby/2.0.0/bundler/gems/vagrant-1e28f1ac31e7/lib/vagrant/config/v1/root.rb
tnargav-1.3.6 lib/vagrant/config/v1/root.rb
tnargav-1.3.3 lib/vagrant/config/v1/root.rb
vagrant-shell-0.2.9 demo/templates/vendor/bundle/ruby/1.9.1/gems/tnargav-1.2.2/lib/vagrant/config/v1/root.rb
tnargav-1.2.3 lib/vagrant/config/v1/root.rb
vagrant-shell-0.2.8 demo/templates/vendor/bundle/ruby/1.9.1/gems/tnargav-1.2.2/lib/vagrant/config/v1/root.rb
vagrant-shell-0.2.6 vendor/bundle/gems/tnargav-1.2.2/lib/vagrant/config/v1/root.rb
vagrant-shell-0.2.5 vendor/bundle/gems/tnargav-1.2.2/lib/vagrant/config/v1/root.rb
tnargav-1.2.2 lib/vagrant/config/v1/root.rb
vagrantup-1.1.3 lib/vagrant/config/v1/root.rb
vagrantup-1.1.2 lib/vagrant/config/v1/root.rb
vagrantup-1.1.1 lib/vagrant/config/v1/root.rb
vagrantup-1.1.0 lib/vagrant/config/v1/root.rb
vagrantup-1.1.4 lib/vagrant/config/v1/root.rb
vagrant-actionio-0.0.9 vendor/bundle/bundler/gems/vagrant-c74251a1d9c0/lib/vagrant/config/v1/root.rb
vagrant-lxc-0.0.1 vendor/vagrant/lib/vagrant/config/v1/root.rb