Class: Vagrant::Action::Builtin::IsState
- Inherits:
-
Object
- Object
- Vagrant::Action::Builtin::IsState
- 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
- #call(env) ⇒ Object
-
#initialize(app, env, check, **opts) ⇒ IsState
constructor
Note: Any of the arguments can be arrays as well.
Constructor Details
#initialize(app, env, check, **opts) ⇒ IsState
Note: Any of the arguments can be arrays as well.
16 17 18 19 20 21 |
# File 'lib/vagrant/action/builtin/is_state.rb', line 16 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
23 24 25 26 27 28 29 30 31 |
# File 'lib/vagrant/action/builtin/is_state.rb', line 23 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 |