Module: VagrantPlugins::OrbStack::Action::MachineValidation

Included in:
Destroy, Halt, SSHRun, Start
Defined in:
lib/vagrant-orbstack/action/machine_validation.rb

Overview

Machine validation mixin for action middleware.

This module provides machine ID validation for Direct Action Pattern actions that interact directly with OrbStack CLI. Include this module when your action needs to validate machine existence before performing CLI operations.

IMPORTANT: Do NOT include this module in Composition Actions that orchestrate other actions. Composition actions delegate validation to their composed actions to avoid redundant checks.

Usage

Direct Actions (Include this module)

  • Create, Halt, Start, Destroy
  • Any action that directly calls Util::OrbStackCLI
  • Actions that manage state cache directly

Composition Actions (Do NOT include)

  • Reload (composes Halt + Start, which both validate)
  • Any action that only orchestrates via Action::Builder

See docs/DESIGN.md "Action Patterns" for complete pattern documentation.

Examples:

Include in a direct action

class Destroy
  include MachineValidation

  def call(env)
    machine_id = validate_machine_id!(env[:machine], 'destroy')
    # ...
  end
end

Instance Method Summary collapse

Instance Method Details

#validate_machine_id!(machine, action_name) ⇒ String

Validate that a machine has a non-nil, non-empty ID.

Parameters:

  • machine (Vagrant::Machine)

    The machine to validate

  • action_name (String)

    The action being performed (for error messages)

Returns:

  • (String)

    The machine ID if valid

Raises:

  • (ArgumentError)

    If machine ID is nil or empty



49
50
51
52
53
54
55
56
# File 'lib/vagrant-orbstack/action/machine_validation.rb', line 49

def validate_machine_id!(machine, action_name)
  machine_id = machine.id
  if machine_id.nil? || machine_id.empty?
    raise ArgumentError,
          "Cannot #{action_name} machine: machine ID is nil or empty"
  end
  machine_id
end