Module: MercuryBanking::Utils::CommandUtils

Defined in:
lib/mercury_banking/utils/command_utils.rb

Overview

Utility methods for command operations

Instance Method Summary collapse

Instance Method Details

#command_exists?(command) ⇒ Boolean

Check if a command exists in the system PATH

Returns:

  • (Boolean)


8
9
10
11
12
13
14
15
16
17
# File 'lib/mercury_banking/utils/command_utils.rb', line 8

def command_exists?(command)
  exts = ENV['PATHEXT'] ? ENV['PATHEXT'].split(';') : ['']
  ENV['PATH'].split(File::PATH_SEPARATOR).each do |path|
    exts.each do |ext|
      exe = File.join(path, "#{command}#{ext}")
      return true if File.executable?(exe) && !File.directory?(exe)
    end
  end
  false
end