Sha256: 02bfdb07b6b543edd843f2cd1c1f186f1ea7c4aa9d9c7d3cd578f34044952e0a

Contents?: true

Size: 1.57 KB

Versions: 7

Compression:

Stored size: 1.57 KB

Contents

# Model the root level Vagrant config object
#
# @see http://docs.vagrantup.com/v2/vagrantfile/index.html
class ConfigBuilder::Model::Root < ConfigBuilder::Model::Base

  include ConfigBuilder::ModelDelegator

  def_model_delegator :vagrant
  def_model_delegator :vms

  # @!attribute [rw] ssh
  #   @return [Hash<Symbol, Object>] The ssh configuration for all VMs
  #   @example
  #     >> config.ssh
  #     => {
  #           :username => 'administrator',
  #           :password => 'vagrant',
  #        }
  def_model_delegator :ssh

  # @!attribute [rw] winrm
  #   @return [Hash<Symbol, Object>] The winrm configuration for all VMs
  #   @example
  #     >> config.winrm
  #     => {
  #           :username => 'administrator',
  #           :password => 'vagrant',
  #        }
  def_model_delegator :winrm

  def initialize
    @defaults = {:vms => [], :vagrant => {}}
  end

  def to_proc
    Proc.new do |root_config|
      eval_models(root_config)
    end
  end

  private

  def eval_vms(root_config)
    attr(:vms).each do |hash|
      v = ConfigBuilder::Model::VM.new_from_hash(hash)
      v.call(root_config)
    end
  end

  def eval_vagrant(root_config)
    if attr(:vagrant).has_key? :host
      root_config.vagrant.host = attr(:vagrant)[:host]
    end
  end

  def eval_ssh(root_config)
    with_attr(:ssh) do |ssh_config|
      f = ConfigBuilder::Model::SSH.new_from_hash(ssh_config)
      f.call(root_config)
    end
  end

  def eval_winrm(root_config)
    if attr(:winrm)
      f = ConfigBuilder::Model::WinRM.new_from_hash(attr(:winrm))
      f.call(root_config)
    end
  end
end

Version data entries

7 entries across 7 versions & 2 rubygems

Version Path
vagrant-config_builder-0.15.1 lib/config_builder/model/root.rb
vagrant-config_builder-0.15.0 lib/config_builder/model/root.rb
vagrant-config_builder-0.14.0 lib/config_builder/model/root.rb
vagrant-config_builder-0.13.0 lib/config_builder/model/root.rb
vagrant-masonry-0.13.0 lib/config_builder/model/root.rb
vagrant-config_builder-0.12.0 lib/config_builder/model/root.rb
vagrant-config_builder-0.11.0 lib/config_builder/model/root.rb