Class: VagrantPlugins::Utm::Action::Customize

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant_utm/action/customize.rb

Overview

This middleware class runs the customizations for the VM.

Instance Method Summary collapse

Constructor Details

#initialize(app, _env, event) ⇒ Customize

Returns a new instance of Customize.



11
12
13
14
# File 'lib/vagrant_utm/action/customize.rb', line 11

def initialize(app, _env, event)
  @app = app
  @event = event
end

Instance Method Details

#call(env) ⇒ Object

rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity



16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
32
33
34
35
36
37
38
39
40
41
42
43
44
45
46
# File 'lib/vagrant_utm/action/customize.rb', line 16

def call(env) # rubocop:disable Metrics/AbcSize,Metrics/CyclomaticComplexity
  customizations = []
  env[:machine].provider_config.customizations.each do |event, command|
    customizations << command if event == @event
  end

  unless customizations.empty?
    env[:ui].info I18n.t("vagrant.actions.vm.customize.running", event: @event)

    # Execute each customization command.
    customizations.each do |command|
      processed_command = command.collect do |arg|
        arg = env[:machine].id if arg == :id
        arg.to_s
      end

      begin
        env[:machine].provider.driver.execute_osa_script(
          processed_command
        )
      rescue VagrantPlugins::Utm::Errors::CommandError => e
        raise Vagrant::Errors::VMCustomizationFailed, {
          command: command,
          error: e.inspect
        }
      end
    end
  end

  @app.call(env)
end