Class: VagrantHosts::ConfigBuilder::Model

Inherits:
ConfigBuilder::Model::Provisioner::Base
  • Object
show all
Defined in:
lib/vagrant-hosts/config_builder/0_x.rb,
lib/vagrant-hosts/config_builder/1_x.rb

Overview

Since:

  • 2.7.0

Instance Attribute Summary collapse

Instance Method Summary collapse

Constructor Details

#initializeModel

Returns a new instance of Model.



17
18
19
20
21
# File 'lib/vagrant-hosts/config_builder/0_x.rb', line 17

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

Instance Attribute Details

#add_localhost_hostnamesObject



13
14
15
# File 'lib/vagrant-hosts/config_builder/0_x.rb', line 13

def add_localhost_hostnames
  @add_localhost_hostnames
end

#autoconfigureObject



11
12
13
# File 'lib/vagrant-hosts/config_builder/0_x.rb', line 11

def autoconfigure
  @autoconfigure
end

#change_hostnameObject



23
# File 'lib/vagrant-hosts/config_builder/1_x.rb', line 23

def_model_attribute :change_hostname

#exportsObject



19
# File 'lib/vagrant-hosts/config_builder/1_x.rb', line 19

def_model_attribute :exports

#hostsObject



9
10
11
# File 'lib/vagrant-hosts/config_builder/0_x.rb', line 9

def hosts
  @hosts
end

#sync_hostsObject



15
16
17
# File 'lib/vagrant-hosts/config_builder/0_x.rb', line 15

def sync_hosts
  @sync_hosts
end

Instance Method Details

#configure_exports(config, val) ⇒ Object

Since:

  • 2.7.0



26
27
28
29
30
31
# File 'lib/vagrant-hosts/config_builder/1_x.rb', line 26

def configure_exports(config, val)
  val.each do |k, v|
    config.exports[k] ||= []
    config.exports[k] += v
  end
end

#configure_hosts(config, val) ⇒ Object

Since:

  • 2.7.0



40
41
42
43
44
# File 'lib/vagrant-hosts/config_builder/1_x.rb', line 40

def configure_hosts(config, val)
  val.each do |(address, aliases)|
    config.add_host(address, aliases)
  end
end

#configure_imports(config, val) ⇒ Object

Since:

  • 2.7.0



34
35
36
37
# File 'lib/vagrant-hosts/config_builder/1_x.rb', line 34

def configure_imports(config, val)
  config.imports += val
  config.imports.uniq!
end

#to_procObject



23
24
25
26
27
28
29
30
31
32
33
34
35
# File 'lib/vagrant-hosts/config_builder/0_x.rb', line 23

def to_proc
  Proc.new do |vm_config|
    vm_config.provision :hosts do |h_config|
      h_config.autoconfigure = attr(:autoconfigure) unless attr(:autoconfigure).nil?
      h_config.add_localhost_hostnames = attr(:add_localhost_hostnames) unless attr(:add_localhost_hostnames).nil?
      h_config.sync_hosts = attr(:sync_hosts) unless attr(:sync_hosts).nil?

      attr(:hosts).each do |(address, aliases)|
        h_config.add_host address, aliases
      end
    end
  end
end