Class: Aruba::Platforms::WindowsWhich::ProgramWhich

Inherits:
Object
  • Object
show all
Defined in:
lib/aruba/platforms/windows_which.rb

Overview

Find path for command

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.match?(program) ⇒ Boolean

Returns:

  • (Boolean)


38
39
40
# File 'lib/aruba/platforms/windows_which.rb', line 38

def self.match?(program)
  Aruba.platform.command?(program)
end

Instance Method Details

#call(program, path) ⇒ Object



42
43
44
45
46
47
48
49
50
51
52
53
54
55
56
57
58
59
60
61
62
63
64
# File 'lib/aruba/platforms/windows_which.rb', line 42

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

    file = File.join(dir, program)
    # Dir[] doesn't handle backslashes properly, so convert them. Also, if
    # the program name doesn't have an extension, try them all.
    file = file.tr("\\", "/")

    found = Dir[file].first

    # Convert all forward slashes to backslashes if supported
    if found && Aruba.platform.executable?(found)
      found.tr!(File::SEPARATOR, File::ALT_SEPARATOR)
      return found
    end
  end

  nil
end