lib/vagrant-invade/action/process.rb in vagrant-invade-0.7.0 vs lib/vagrant-invade/action/process.rb in vagrant-invade-0.8.0

- old
+ new

@@ -16,24 +16,28 @@ @invade_machine = Hash.new @invade_machine_part = Hash.new @invade_vagrantfile = Hash.new @generate = @env[:invade_generate] + @build_quiet = @env[:invade_build_quiet] @quiet = @env[:invade_validate_quiet] @logger = Log4r::Logger.new('vagrant::invade::action::validate') end def call(env) config = env[:invade] - # Remove empty Hashes - config = config.compact(config) + # If config data is not a hash, something went totally wrong or it's not correct YAML + # This should never happen - but better to stop the progress here. + if !config.is_a?(Hash) + raise "Something went wrong parsing your configuration file. Is your YAML in a correct format?" + end config.each do |config_key, config_data| - if config_key == 'machines' + if config_key == 'machine' process_machines(config_data) else process_vagrant_part(config_key, config_data) end end @@ -41,30 +45,31 @@ @env[:invade]['vagrantfile'] = generate( data: @invade_vagrantfile, generator_type: Invade::Generator::Type::VAGRANTFILE ) if @generate - @env[:invade].delete('machines') + @env[:invade].delete('machine') @app.call(env) end private - def process_machines(machines) - + def process_machines(machine) + # Iterate over machine configurations - machines.each_with_index do |(machine, machine_data), _| + machine.each_with_index do |(machine, machine_data), _| process_machine(machine, machine_data) end - @invade_vagrantfile['machines'] = @invade_machine - @env[:ui].success "\n[Invade]: Processed #{machines.count} machine(s)." + @invade_vagrantfile['machine'] = @invade_machine + @env[:ui].success "\n[Invade]: Processed #{machine.count} machine(s)." unless @build_quiet end def process_machine(machine_name, machine_data) + # Iterate over each machine part configuration machine_data.each do |machine_part_name, machine_part_data| @env[:ui].info("\n[Invade][Machine: #{machine_name.upcase}]: Validating #{machine_part_name.upcase} part...") unless @quiet if machine_part_data.depth > 1 @@ -80,9 +85,10 @@ ) end end def process_machine_part(machine, machine_part_name, machine_part_data) + validated_data = validate('Machine', machine_part_name, machine_part_data, machine_part_data.depth) @invade_machine_part[machine_part_name] = generate( machine_name: machine, part_type: machine_part_name, data: validated_data,