Module: Which
- Included in:
- LaunchAgentManagementInstanceMethods
- Defined in:
- lib/kanseishitsu/which.rb
Overview
Define module Which
Instance Method Summary collapse
- #executable?(exe) ⇒ Boolean
- #explicit_which(cmd) ⇒ Object
-
#find_executable_in_path(cmd) ⇒ Object
Find the full path to a given executable in the PATH system environment variable.
- #portable_which(cmd) ⇒ Object (also: #which)
Instance Method Details
#executable?(exe) ⇒ Boolean
22 23 24 |
# File 'lib/kanseishitsu/which.rb', line 22 def executable?(exe) !exe.empty? && File.executable?(exe) && !File.directory?(exe) end |
#explicit_which(cmd) ⇒ Object
26 27 28 29 30 31 |
# File 'lib/kanseishitsu/which.rb', line 26 def explicit_which(cmd) exe = `which #{cmd}`.chomp executable?(exe) ? exe : nil rescue Errno::ENOENT => _e nil end |
#find_executable_in_path(cmd) ⇒ Object
Find the full path to a given executable in the PATH system environment variable
13 14 15 16 17 18 19 20 |
# File 'lib/kanseishitsu/which.rb', line 13 def find_executable_in_path(cmd) return if cmd.nil? directory = ENV['PATH'].split(File::PATH_SEPARATOR).find do |dir| File.executable?(File.join(dir, cmd)) end directory.nil? ? nil : File.join(directory, cmd) end |
#portable_which(cmd) ⇒ Object Also known as: which
33 34 35 |
# File 'lib/kanseishitsu/which.rb', line 33 def portable_which(cmd) explicit_which(cmd) || find_executable_in_path(cmd) end |