Class: Hirb::Util

Inherits:
Object
  • Object
show all
Defined in:
lib/spirit_hands/hirb/fixes/util.rb

Class Method Summary collapse

Class Method Details

.command_exists?(command) ⇒ Boolean

Determines if a shell command exists by searching for it in ENV. (Fixed version)

Returns:

  • (Boolean)


7
8
9
10
11
12
13
14
15
16
17
18
# File 'lib/spirit_hands/hirb/fixes/util.rb', line 7

def command_exists?(command)
  if c = Pathname.new(command)
    return true if c.absolute? && c.exist?
  end
  executable_file_exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
  ENV['PATH'].split(File::PATH_SEPARATOR).any? do |d|
    executable_file_exts.any? do |ext|
      f = File.expand_path(command + ext, d)
      File.executable?(f) && !File.directory?(f)
    end
  end
end