lib/acouchi/which.rb in acouchi-0.0.8 vs lib/acouchi/which.rb in acouchi-0.0.9
- old
+ new
@@ -1,29 +1,12 @@
module Acouchi
class Which
- def self.find_executable *aliases
- if executable = aliases.find {|a| which? a}
+ def self.find_executable name
+ require "ptools"
+ if executable = File.which(name)
executable
else
raise %{Couldn't find any matches for the aliases "#{aliases.join(", ")}"}
end
end
-
- private
- def self.which? command
- ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
- exe = File.join(path, "#{command}")
- return exe if executable? exe
- end
- return nil
- end
-
- def self.executable? file
- return true if File.executable?(file)
- extensions = ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : []
- File.exist?(file) &&
- File.file?(file) &&
- extensions.any? &&
- extensions.any? {|e| file.downcase.end_with?(e.downcase)}
- end
end
end