lib/acouchi/which.rb in acouchi-0.0.7 vs lib/acouchi/which.rb in acouchi-0.0.8
- old
+ new
@@ -8,16 +8,22 @@
end
end
private
def self.which? command
- exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
- exts.each { |ext|
- exe = "#{path}/#{command}#{ext}"
- return exe if File.executable? exe
- }
+ 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