Class: Aruba::Platforms::UnixWhich::ProgramWhich

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

Overview

Find path for command

Class Method Summary collapse

Instance Method Summary collapse

Class Method Details

.match?(program) ⇒ Boolean

Returns:

  • (Boolean)

35
36
37
# File 'lib/aruba/platforms/unix_which.rb', line 35

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

Instance Method Details

#call(program, path) ⇒ Object


39
40
41
42
43
44
45
46
47
48
49
50
# 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