Class: Vagrant::Action::Builtin::IsState

Inherits:
Object
  • Object
show all
Defined in:
lib/vagrant/action/builtin/is_state.rb

Overview

This middleware is meant to be used with Call and can check if a machine is in the given state ID.

Instance Method Summary collapse

Constructor Details

#initialize(app, env, check, **opts) ⇒ IsState

Note: Any of the arguments can be arrays as well.

Parameters:

  • target_state (Symbol)

    The target state ID that means that the machine was properly shut down.

  • source_state (Symbol)

    The source state ID that the machine must be in to be shut down.


13
14
15
16
17
18
# File 'lib/vagrant/action/builtin/is_state.rb', line 13

def initialize(app, env, check, **opts)
  @app    = app
  @logger = Log4r::Logger.new("vagrant::action::builtin::is_state")
  @check  = check
  @invert = !!opts[:invert]
end

Instance Method Details

#call(env) ⇒ Object


20
21
22
23
24
25
26
27
28
# File 'lib/vagrant/action/builtin/is_state.rb', line 20

def call(env)
  @logger.debug("Checking if machine state is '#{@check}'")
  state = env[:machine].state.id
  @logger.debug("-- Machine state: #{state}")

  env[:result] = @check == state
  env[:result] = !env[:result] if @invert
  @app.call(env)
end