Sha256: f349d27acacd3bc77fd3d1542aa94549eafc4ecc4e08f63a2d9a132b7b71088b

Contents?: true

Size: 1.79 KB

Versions: 6

Compression:

Stored size: 1.79 KB

Contents

module VagrantPlugins
  module Invade
    module Generator

      autoload :Type, 'vagrant-invade/generator/type'

      class Generator

        attr_accessor :type

        def initialize(env)
          @env = env
          @type = Type::VAGRANT_PART

          @logger = Log4r::Logger.new('vagrant::invade::generator::vagrant')
        end
        
        def generate(machine: nil, part: nil, type: nil, data: nil)

          begin

            # Generates the templates with validated data
            case @type
              when Invade::Generator::Type::VAGRANTFILE
                generated_data = InvadeModule::Vagrant::Vagrantfile.new(data).build

              when Invade::Generator::Type::VAGRANT_PART
                generator_class_name = type.split('_').collect(&:capitalize).join
                generated_data = InvadeModule.const_get(generator_class_name).new(data).build

              when Invade::Generator::Type::MACHINE
                generated_data = InvadeModule::Vagrant::Machine.new(machine, data).build

              when Invade::Generator::Type::MACHINE_NESTED_PART
                type_formatted = type.split('_').collect(&:capitalize).join
                part_formatted = part.split('_').collect(&:capitalize).join
                generator_class_name = part_formatted + '::' + type_formatted
                generated_data = InvadeModule.const_get(generator_class_name).new(machine, data).build

              else
                generator_class_name = type.split('_').collect(&:capitalize).join
                generated_data = InvadeModule.const_get(generator_class_name).new(machine, data).build
            end

            return generated_data
          rescue StandardError => e
            @logger.error e
            fail e
          end
        end

      end

    end
  end
end

Version data entries

6 entries across 6 versions & 1 rubygems

Version Path
vagrant-invade-0.8.0 lib/vagrant-invade/generator.rb
vagrant-invade-0.7.0 lib/vagrant-invade/generator.rb
vagrant-invade-0.6.4 lib/vagrant-invade/generator.rb
vagrant-invade-0.6.3 lib/vagrant-invade/generator.rb
vagrant-invade-0.6.2 lib/vagrant-invade/generator.rb
vagrant-invade-0.6.1 lib/vagrant-invade/generator.rb