Class: Vagrant::Notify::Action::NotifyProvisioningStatus

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-notify/action/notify_provisioning_status.rb

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ NotifyProvisioningStatus

Returns a new instance of NotifyProvisioningStatus.



5
6
7
# File 'lib/vagrant-notify/action/notify_provisioning_status.rb', line 5

def initialize(app, env)
  @app = app
end

Instance Method Details

#call(env) ⇒ Object



9
10
11
12
13
14
15
16
17
18
19
20
21
# File 'lib/vagrant-notify/action/notify_provisioning_status.rb', line 9

def call(env)
  message = notify_provision_messages(env) unless env[:machine].config.notify.enable == false
  system(message[:start]) unless env[:machine].config.notify.enable == false

  begin
    @app.call(env)
  rescue => msg
    system("notify-send '[#{env[:machine].name}] \"#{env[:provisioner_name]}\" provision failed!'") unless env[:machine].config.notify.enable == false
    env[:machine].ui.error("#{msg}")
  else
    system(message[:end]) unless env[:machine].config.notify.enable == false
  end
end

#notify_provision_messages(env) ⇒ Object



23
24
25
26
27
28
29
30
31
32
33
# File 'lib/vagrant-notify/action/notify_provisioning_status.rb', line 23

def notify_provision_messages(env)
  message = Hash.new
  if env[:provisioner_name].to_s == 'shell' and env[:provisioner].config.name
    message[:start] = "notify-send '[#{env[:machine].name}] Provisioning with \"#{env[:provisioner_name]} (#{env[:provisioner].config.name})\"...'"
    message[:end] = "notify-send '[#{env[:machine].name}] Finished provisioning with \"#{env[:provisioner_name]} (#{env[:provisioner].config.name})\"'" 
  else
    message[:start] = "notify-send '[#{env[:machine].name}] Provisioning with \"#{env[:provisioner_name]}\"...'"
    message[:end] = "notify-send '[#{env[:machine].name}] Finished provisioning with \"#{env[:provisioner_name]}\"'"
  end
  return message
end