Class: VagrantPlugins::Skytap::Action::ExistenceCheck

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant-skytap/action/existence_check.rb

Overview

This can be used with “Call” built-in to check if the environment is created and branch in the middleware.

Instance Method Summary collapse

Constructor Details

#initialize(app, env) ⇒ ExistenceCheck

Returns a new instance of ExistenceCheck.


9
10
11
12
# File 'lib/vagrant-skytap/action/existence_check.rb', line 9

def initialize(app, env)
  @app = app
  @logger = Log4r::Logger.new("vagrant_skytap::action::existence_check")
end

Instance Method Details

#call(env) ⇒ Object


14
15
16
17
18
19
20
21
22
23
24
25
26
27
28
29
30
31
# File 'lib/vagrant-skytap/action/existence_check.rb', line 14

def call(env)
  environment = env[:environment]
  env[:result] = if !environment
    :missing_environment
  elsif environment.vms.count == 0
    :no_vms
  elsif !environment.current_vm
    # Could be confusing. The *current* vm is not present. This response also implies that there are other vms.
    :missing_vm
  elsif environment.vms.count == 1
    :solitary_vm
  else
    :one_of_many_vms
  end
  @logger.debug("ExistenceCheck returning #{env[:result]}")

  @app.call(env)
end