class Aruba::Platforms::UnixWhich::ProgramWhich

Find path for command

Public Class Methods

match?(program) click to toggle source
# File lib/aruba/platforms/unix_which.rb, line 35
def self.match?(program)
  Aruba.platform.command?(program)
end

Public Instance Methods

call(program, path) click to toggle source
# File lib/aruba/platforms/unix_which.rb, line 39
def call(program, path)
  # Iterate over each path glob the dir + program.
  path.split(File::PATH_SEPARATOR).each do |dir|
    dir = Aruba.platform.expand_path(dir, Dir.getwd)
    next unless Aruba.platform.exist?(dir) # In case of bogus second argument

    found = Dir[File.join(dir, program)].first
    return found if found && Aruba.platform.executable?(found)
  end

  nil
end