Module: Byebug::Helpers::BinHelper

Included in:
RestartCommand, Runner
Defined in:
lib/byebug/helpers/bin.rb

Overview

Utilities for interaction with executables

Instance Method Summary collapse

Instance Method Details

#executable_file_extensionsObject



38
39
40
# File 'lib/byebug/helpers/bin.rb', line 38

def executable_file_extensions
  ENV["PATHEXT"] ? ENV["PATHEXT"].split(";") : [""]
end

#find_executable(path, cmd) ⇒ Object



24
25
26
27
28
29
30
31
32
# File 'lib/byebug/helpers/bin.rb', line 24

def find_executable(path, cmd)
  executable_file_extensions.each do |ext|
    exe = File.expand_path(cmd + ext, path)

    return exe if real_executable?(exe)
  end

  nil
end

#real_executable?(file) ⇒ Boolean

Returns:

  • (Boolean)


42
43
44
# File 'lib/byebug/helpers/bin.rb', line 42

def real_executable?(file)
  File.executable?(file) && !File.directory?(file)
end

#search_pathsObject



34
35
36
# File 'lib/byebug/helpers/bin.rb', line 34

def search_paths
  ENV["PATH"].split(File::PATH_SEPARATOR)
end

#which(cmd) ⇒ Object

Cross-platform way of finding an executable in the $PATH. Adapted from: gist.github.com/steakknife/88b6c3837a5e90a08296



13
14
15
16
17
18
19
20
21
22
# File 'lib/byebug/helpers/bin.rb', line 13

def which(cmd)
  return File.expand_path(cmd) if File.exist?(cmd)

  [nil, *search_paths].each do |path|
    exe = find_executable(path, cmd)
    return exe if exe
  end

  nil
end