Class: Aidp::Interfaces::PathBinaryChecker

Inherits:
Object
  • Object
show all
Includes:
BinaryCheckerInterface
Defined in:
lib/aidp/interfaces/binary_checker_interface.rb

Overview

PathBinaryChecker checks the system PATH for binaries. This is the standard implementation used by AIDP.

Examples:

Creating a checker

checker = PathBinaryChecker.new
checker.available?("ruby") # => true
checker.path_for("ruby")   # => "/usr/bin/ruby"

Instance Method Summary collapse

Instance Method Details

#available?(binary_name) ⇒ Boolean

Check if a binary is available in the system PATH.

Parameters:

  • binary_name (String)

    the name of the binary to check

Returns:

  • (Boolean)

    true if the binary is executable and in PATH



113
114
115
# File 'lib/aidp/interfaces/binary_checker_interface.rb', line 113

def available?(binary_name)
  !path_for(binary_name).nil?
end

#path_for(binary_name) ⇒ String?

Get the full path to a binary. Searches the PATH environment variable for the binary.

Parameters:

  • binary_name (String)

    the name of the binary to find

Returns:

  • (String, nil)

    the full path to the binary, or nil if not found



122
123
124
125
126
127
128
129
130
131
132
133
134
135
136
137
# File 'lib/aidp/interfaces/binary_checker_interface.rb', line 122

def path_for(binary_name)
  return nil if binary_name.nil? || binary_name.empty?

  # Get extensions to check (Windows support)
  extensions = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""]

  # Search each PATH directory
  ENV["PATH"].to_s.split(File::PATH_SEPARATOR).each do |dir|
    extensions.each do |ext|
      path = File.join(dir, "#{binary_name}#{ext}")
      return path if File.executable?(path) && !File.directory?(path)
    end
  end

  nil
end