Module: VagrantPlugins::VagrantJson

Defined in:
lib/vagrant-json.rb,
lib/vagrant-json/plugin.rb,
lib/vagrant-json/version.rb,
lib/vagrant-json/config/json.rb,
lib/vagrant-json/command/init.rb,
lib/vagrant-json/command/root.rb

Defined Under Namespace

Modules: Command, Config Classes: Plugin

Constant Summary collapse

VERSION =
"0.1.1"

Class Method Summary collapse

Class Method Details

.apply_settings(vm, yml) ⇒ Object



12
13
14
15
16
17
18
19
20
21
22
23
# File 'lib/vagrant-json.rb', line 12

def self.apply_settings(vm, yml)
  yml.each do |key0, value0|
    if !value0.is_a?(Hash) # If it's a setting,
      vm.send("#{key0}=".to_sym, value0) # we set it directly.
    else # Otherwise,
      method_object = vm.method("#{key0}".to_sym) # we're invoking a method
      value0.each do |key1, value1| # and each setting
        method_object.call("#{key1}".to_sym, value1) # needs to be passed to the method.
      end
    end
  end
end

.source_rootObject



8
9
10
# File 'lib/vagrant-json.rb', line 8

def self.source_root
  @source_root ||= Pathname.new(File.expand_path '../../', __FILE__)
end

.up!(config) ⇒ Object



25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
47
48
49
50
51
# File 'lib/vagrant-json.rb', line 25

def self.up!(config)
  require 'json'
  require 'yaml'

  vms = []

  if config.directory
    # Grab these files only
  end

  files = Dir.glob("*.{json,yaml,yml}").map {|f| JSON.parse(YAML.load_file(f).to_json, symbolize_names: true)}

  files.each do |file|
    if file[:boxes]
      vms.concat(file[:boxes])
    else
      vms << file
    end
  end

  vms.each do |vm|
    config.vm.define "#{vm[:hostname]}" do |vm_config|
      apply_settings(vm_config.vm, vm)
    end
  end

end