class NativePackageInstaller::ExecutableFinder

Public Class Methods

exist?(basename) click to toggle source
# File lib/native-package-installer/executable-finder.rb, line 25
def exist?(basename)
  new(basename).exist?
end
find(basename) click to toggle source
# File lib/native-package-installer/executable-finder.rb, line 21
def find(basename)
  new(basename).find
end
new(basename) click to toggle source
# File lib/native-package-installer/executable-finder.rb, line 30
def initialize(basename)
  @basename = basename
end

Public Instance Methods

exist?() click to toggle source
# File lib/native-package-installer/executable-finder.rb, line 49
def exist?
  not find.nil?
end
find() click to toggle source
# File lib/native-package-installer/executable-finder.rb, line 34
def find
  extensions = detect_extensions
  paths.each do |path|
    executable_file = File.join(path, @basename)
    return executable_file if executable?(executable_file)
    extensions.each do |extension|
      executable_file_with_extension = executable_file + extension
      if executable?(executable_file_with_extension)
        return executable_file_with_extension
      end
    end
  end
  nil
end

Private Instance Methods

detect_extensions() click to toggle source
# File lib/native-package-installer/executable-finder.rb, line 63
def detect_extensions
  exts = RbConfig::CONFIG["EXECUTABLE_EXTS"]
  return exts.split if exts
  ext = RbConfig::CONFIG["EXEEXT"]
  return [ext] if ext
  []
end
executable?(path) click to toggle source
# File lib/native-package-installer/executable-finder.rb, line 71
def executable?(path)
  begin
    stat = File.stat(path)
  rescue SystemCallError
    false
  else
    stat.file? and stat.executable?
  end
end
paths() click to toggle source
# File lib/native-package-installer/executable-finder.rb, line 54
def paths
  path_env = ENV["PATH"]
  if path_env
    path_env.split(File::PATH_SEPARATOR)
  else
    ["/usr/local/bin", "/usr/bin", "/bin"]
  end
end